From d27a2a4d53a2c7c21f272159bb112dd54803a4ed Mon Sep 17 00:00:00 2001 From: Mauritz Date: Thu, 25 Jul 2024 17:34:06 +0200 Subject: [PATCH] feat: calculate height of dialog --- lib/src/view/user/game_history_screen.dart | 41 +++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/src/view/user/game_history_screen.dart b/lib/src/view/user/game_history_screen.dart index dc6e9a76a2..9b4f902a60 100644 --- a/lib/src/view/user/game_history_screen.dart +++ b/lib/src/view/user/game_history_screen.dart @@ -248,8 +248,11 @@ class _MultipleChoiceFilter extends StatelessWidget { choices: choices, selectedItems: selectedItems, choiceLabel: choiceLabel, - onChanged: onChanged, - ), + ).then((value) { + if (value != null) { + onChanged(value); + } + }), style: TextButton.styleFrom( backgroundColor: selectedItems.isEmpty ? Theme.of(context).colorScheme.secondary @@ -291,23 +294,35 @@ Future?> showMultipleChoiceFilter( required Iterable choices, required ISet selectedItems, required String Function(T choice) choiceLabel, - required void Function(ISet value) onChanged, }) { return showAdaptiveDialog>( context: context, builder: (context) { ISet items = selectedItems; + const paddingTop = 12.0; return AlertDialog.adaptive( - contentPadding: const EdgeInsets.only(top: 12), + contentPadding: const EdgeInsets.only(top: paddingTop), scrollable: true, content: StatefulBuilder( builder: (BuildContext context, StateSetter setState) { - final size = MediaQuery.sizeOf(context); + final width = MediaQuery.sizeOf(context).width; + const aspectRatio = 4.0; + const itemsPerRow = 2; + const verticalSpacing = 8.0; + const horizontalSpacing = 8.0; + + final chipWidth = width / itemsPerRow - horizontalSpacing; + final chipHeight = chipWidth / aspectRatio + verticalSpacing; + final rows = (choices.length / itemsPerRow).ceil(); + final height = chipHeight * rows - verticalSpacing - paddingTop; return SizedBox( - width: size.width, - height: size.height / 2, + width: width, + height: height, child: GridView.count( - crossAxisCount: 2, + childAspectRatio: aspectRatio, + crossAxisCount: itemsPerRow, + mainAxisSpacing: verticalSpacing, + crossAxisSpacing: horizontalSpacing, children: choices .map( (choice) => FilterChip( @@ -336,10 +351,7 @@ Future?> showMultipleChoiceFilter( CupertinoDialogAction( isDefaultAction: true, child: Text(context.l10n.mobileOkButton), - onPressed: () { - onChanged(items); - Navigator.of(context).pop(items); - }, + onPressed: () => Navigator.of(context).pop(items), ), ] : [ @@ -349,10 +361,7 @@ Future?> showMultipleChoiceFilter( ), TextButton( child: Text(context.l10n.mobileOkButton), - onPressed: () { - onChanged(items); - Navigator.of(context).pop(items); - }, + onPressed: () => Navigator.of(context).pop(items), ), ], );