Skip to content

Commit

Permalink
feat: calculate height of dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauritz8 committed Jul 25, 2024
1 parent 5fddd43 commit d27a2a4
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions lib/src/view/user/game_history_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ class _MultipleChoiceFilter<T extends Enum> 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
Expand Down Expand Up @@ -291,23 +294,35 @@ Future<ISet<T>?> showMultipleChoiceFilter<T extends Enum>(
required Iterable<T> choices,
required ISet<T> selectedItems,
required String Function(T choice) choiceLabel,
required void Function(ISet<T> value) onChanged,
}) {
return showAdaptiveDialog<ISet<T>>(
context: context,
builder: (context) {
ISet<T> 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(
Expand Down Expand Up @@ -336,10 +351,7 @@ Future<ISet<T>?> showMultipleChoiceFilter<T extends Enum>(
CupertinoDialogAction(
isDefaultAction: true,
child: Text(context.l10n.mobileOkButton),
onPressed: () {
onChanged(items);
Navigator.of(context).pop(items);
},
onPressed: () => Navigator.of(context).pop(items),
),
]
: [
Expand All @@ -349,10 +361,7 @@ Future<ISet<T>?> showMultipleChoiceFilter<T extends Enum>(
),
TextButton(
child: Text(context.l10n.mobileOkButton),
onPressed: () {
onChanged(items);
Navigator.of(context).pop(items);
},
onPressed: () => Navigator.of(context).pop(items),
),
],
);
Expand Down

0 comments on commit d27a2a4

Please sign in to comment.