Skip to content

Commit

Permalink
Improve dialogs and sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Jul 30, 2023
1 parent 9a18559 commit 9687303
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 102 deletions.
75 changes: 37 additions & 38 deletions lib/src/view/game/game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
},
),
],
),
Expand Down
120 changes: 56 additions & 64 deletions lib/src/widgets/adaptive_action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,74 +81,66 @@ Future<T?> showMaterialActionSheet<T>({
bool isDismissible = true,
}) {
final defaultTextStyle =
Theme.of(context).textTheme.titleLarge ?? const TextStyle(fontSize: 20);
return showModalBottomSheet<T>(
Theme.of(context).textTheme.titleMedium ?? const TextStyle(fontSize: 20);
return showDialog<T>(
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: <Widget>[
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: <Widget>[
if (title != null) ...[
Padding(
padding: const EdgeInsets.all(16.0),
child: Center(child: title),
),
],
...actions.mapIndexed<Widget>((index, action) {
return InkWell(
borderRadius: BorderRadius.vertical(
top: Radius.circular(
index == 0 ? 28 : 0,
),
],
...actions.mapIndexed<Widget>((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!,
],
],
),
),
);
}),
],
),
),
);
Expand Down

0 comments on commit 9687303

Please sign in to comment.