From ac12e98df9d559d970cb6e5944bd90d61d5b036e Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 9 Jul 2023 15:04:58 +0200 Subject: [PATCH] neon: Use theme extension for tablet layout --- packages/neon/neon/lib/src/pages/login.dart | 5 ++-- .../lib/src/pages/login_check_account.dart | 5 ++-- .../src/pages/login_check_server_status.dart | 5 ++-- packages/neon/neon/lib/src/utils/theme.dart | 23 +++++++++++++++---- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/neon/neon/lib/src/pages/login.dart b/packages/neon/neon/lib/src/pages/login.dart index bdebeefd..64e57783 100644 --- a/packages/neon/neon/lib/src/pages/login.dart +++ b/packages/neon/neon/lib/src/pages/login.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:neon/l10n/localizations.dart'; import 'package:neon/src/models/branding.dart'; import 'package:neon/src/router.dart'; +import 'package:neon/src/utils/theme.dart'; import 'package:neon/src/utils/validators.dart'; import 'package:neon/src/widgets/nextcloud_logo.dart'; import 'package:provider/provider.dart'; @@ -59,9 +60,7 @@ class _LoginPageState extends State { ), body: Center( child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: 640, - ), + constraints: Theme.of(context).extension()?.tabletLayout ?? const BoxConstraints(), child: Scrollbar( interactive: true, child: SingleChildScrollView( diff --git a/packages/neon/neon/lib/src/pages/login_check_account.dart b/packages/neon/neon/lib/src/pages/login_check_account.dart index 279abfcf..c425ef30 100644 --- a/packages/neon/neon/lib/src/pages/login_check_account.dart +++ b/packages/neon/neon/lib/src/pages/login_check_account.dart @@ -6,6 +6,7 @@ import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/login_check_account.dart'; import 'package:neon/src/models/account.dart'; import 'package:neon/src/router.dart'; +import 'package:neon/src/utils/theme.dart'; import 'package:neon/src/widgets/account_tile.dart'; import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; @@ -57,9 +58,7 @@ class _LoginCheckAccountPageState extends State { child: Padding( padding: const EdgeInsets.all(10), child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: 640, - ), + constraints: Theme.of(context).extension()?.tabletLayout ?? const BoxConstraints(), child: ResultBuilder.behaviorSubject( stream: bloc.state, builder: (final context, final state) => Column( diff --git a/packages/neon/neon/lib/src/pages/login_check_server_status.dart b/packages/neon/neon/lib/src/pages/login_check_server_status.dart index 4e908948..205fd377 100644 --- a/packages/neon/neon/lib/src/pages/login_check_server_status.dart +++ b/packages/neon/neon/lib/src/pages/login_check_server_status.dart @@ -3,6 +3,7 @@ import 'package:neon/l10n/localizations.dart'; import 'package:neon/src/bloc/result.dart'; import 'package:neon/src/bloc/result_builder.dart'; import 'package:neon/src/blocs/login_check_server_status.dart'; +import 'package:neon/src/utils/theme.dart'; import 'package:neon/src/widgets/exception.dart'; import 'package:neon/src/widgets/linear_progress_indicator.dart'; import 'package:neon/src/widgets/validation_tile.dart'; @@ -45,9 +46,7 @@ class _LoginCheckServerStatusPageState extends State child: Padding( padding: const EdgeInsets.all(10), child: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: 640, - ), + constraints: Theme.of(context).extension()?.tabletLayout ?? const BoxConstraints(), child: ResultBuilder.behaviorSubject( stream: bloc.state, builder: (final context, final state) => Column( diff --git a/packages/neon/neon/lib/src/utils/theme.dart b/packages/neon/neon/lib/src/utils/theme.dart index 28e87a0d..c72c0682 100644 --- a/packages/neon/neon/lib/src/utils/theme.dart +++ b/packages/neon/neon/lib/src/utils/theme.dart @@ -48,7 +48,11 @@ class AppTheme { snackBarTheme: _snackBarTheme, dividerTheme: _dividerTheme, extensions: [ - const NeonTheme(), + const NeonTheme( + tabletLayout: BoxConstraints( + maxWidth: 640, + ), + ), ...?appThemes, ], ); @@ -70,16 +74,27 @@ class AppTheme { @internal @immutable class NeonTheme extends ThemeExtension { - const NeonTheme(); + const NeonTheme({ + required this.tabletLayout, + }); + + final BoxConstraints? tabletLayout; @override - NeonTheme copyWith() => const NeonTheme(); + NeonTheme copyWith({ + final BoxConstraints? tabletLayout, + }) => + NeonTheme( + tabletLayout: tabletLayout ?? this.tabletLayout, + ); @override NeonTheme lerp(final NeonTheme? other, final double t) { if (other is! NeonTheme) { return this; } - return const NeonTheme(); + return NeonTheme( + tabletLayout: BoxConstraints.lerp(tabletLayout, other.tabletLayout, t), + ); } }