From 9687303eea5c63e26eacee8d5673a951afbe4078 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Sun, 30 Jul 2023 13:15:52 +0200 Subject: [PATCH] Improve dialogs and sheets --- lib/src/view/game/game_screen.dart | 75 +++++++------ lib/src/widgets/adaptive_action_sheet.dart | 120 ++++++++++----------- 2 files changed, 93 insertions(+), 102 deletions(-) diff --git a/lib/src/view/game/game_screen.dart b/lib/src/view/game/game_screen.dart index 686c9399f8..00835fc3ba 100644 --- a/lib/src/view/game/game_screen.dart +++ b/lib/src/view/game/game_screen.dart @@ -22,7 +22,6 @@ import 'package:lichess_mobile/src/widgets/platform.dart'; import 'package:lichess_mobile/src/widgets/board_table.dart'; import 'package:lichess_mobile/src/widgets/countdown_clock.dart'; import 'package:lichess_mobile/src/widgets/player.dart'; -import 'package:lichess_mobile/src/widgets/list.dart'; import 'package:lichess_mobile/src/widgets/adaptive_dialog.dart'; import 'package:lichess_mobile/src/widgets/settings.dart'; import 'package:lichess_mobile/src/utils/immersive_mode.dart'; @@ -391,44 +390,44 @@ class _Preferences extends ConsumerWidget { final boardPrefs = ref.watch(boardPreferencesProvider); return SafeArea( - child: Column( - mainAxisSize: MainAxisSize.min, + child: ListView( children: [ - ListSection( - hasLeading: false, - showDivider: false, - children: [ - SwitchSettingTile( - title: Text(context.l10n.sound), - value: isSoundEnabled, - onChanged: (value) { - ref - .read(generalPreferencesProvider.notifier) - .toggleSoundEnabled(); - }, - ), - SwitchSettingTile( - title: const Text('Haptic feedback'), - value: boardPrefs.hapticFeedback, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleHapticFeedback(); - }, - ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesPieceAnimation, - maxLines: 2, - ), - value: boardPrefs.pieceAnimation, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .togglePieceAnimation(); - }, - ), - ], + Padding( + padding: Styles.bodyPadding, + child: Text( + context.l10n.preferencesPreferences, + style: Styles.title, + ), + ), + SwitchSettingTile( + title: Text(context.l10n.sound), + value: isSoundEnabled, + onChanged: (value) { + ref + .read(generalPreferencesProvider.notifier) + .toggleSoundEnabled(); + }, + ), + SwitchSettingTile( + title: const Text('Haptic feedback'), + value: boardPrefs.hapticFeedback, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleHapticFeedback(); + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesPieceAnimation, + maxLines: 2, + ), + value: boardPrefs.pieceAnimation, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .togglePieceAnimation(); + }, ), ], ), diff --git a/lib/src/widgets/adaptive_action_sheet.dart b/lib/src/widgets/adaptive_action_sheet.dart index 5efc474da6..8d55f12152 100644 --- a/lib/src/widgets/adaptive_action_sheet.dart +++ b/lib/src/widgets/adaptive_action_sheet.dart @@ -81,74 +81,66 @@ Future showMaterialActionSheet({ bool isDismissible = true, }) { final defaultTextStyle = - Theme.of(context).textTheme.titleLarge ?? const TextStyle(fontSize: 20); - return showModalBottomSheet( + Theme.of(context).textTheme.titleMedium ?? const TextStyle(fontSize: 20); + return showDialog( context: context, - isDismissible: isDismissible, - enableDrag: isDismissible, - isScrollControlled: true, + barrierDismissible: isDismissible, builder: (BuildContext context) { - final double screenHeight = MediaQuery.of(context).size.height; - return SafeArea( - child: WillPopScope( - onWillPop: () async => isDismissible, - child: ConstrainedBox( - constraints: BoxConstraints( - maxHeight: screenHeight - (screenHeight / 10), - ), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisSize: MainAxisSize.min, - children: [ - if (title != null) ...[ - Padding( - padding: const EdgeInsets.all(16.0), - child: Center(child: title), + return Dialog( + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.min, + children: [ + if (title != null) ...[ + Padding( + padding: const EdgeInsets.all(16.0), + child: Center(child: title), + ), + ], + ...actions.mapIndexed((index, action) { + return InkWell( + borderRadius: BorderRadius.vertical( + top: Radius.circular( + index == 0 ? 28 : 0, ), - ], - ...actions.mapIndexed((index, action) { - return InkWell( - borderRadius: BorderRadius.vertical( - top: Radius.circular( - index == 0 ? 28 : 0, - ), - ), - onTap: () { - action.onPressed(context); - if (action.dismissOnPress) { - Navigator.of(context).pop(); - } - }, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Row( - children: [ - if (action.leading != null) ...[ - action.leading!, - const SizedBox(width: 15), - ], - Expanded( - child: DefaultTextStyle( - style: defaultTextStyle, - textAlign: action.leading != null - ? TextAlign.start - : TextAlign.center, - child: action.label, - ), - ), - if (action.trailing != null) ...[ - const SizedBox(width: 10), - action.trailing!, - ], - ], + bottom: Radius.circular( + index == actions.length - 1 ? 28 : 0, + ), + ), + onTap: () { + action.onPressed(context); + if (action.dismissOnPress) { + Navigator.of(context).pop(); + } + }, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Row( + children: [ + if (action.leading != null) ...[ + action.leading!, + const SizedBox(width: 15), + ], + Expanded( + child: DefaultTextStyle( + style: defaultTextStyle, + textAlign: action.leading != null + ? TextAlign.start + : TextAlign.center, + child: action.label, + ), ), - ), - ); - }), - ], - ), - ), + if (action.trailing != null) ...[ + const SizedBox(width: 10), + action.trailing!, + ], + ], + ), + ), + ); + }), + ], ), ), );