diff --git a/lib/src/view/user/game_history_screen.dart b/lib/src/view/user/game_history_screen.dart index a84fc56bd0..3b3c79f269 100644 --- a/lib/src/view/user/game_history_screen.dart +++ b/lib/src/view/user/game_history_screen.dart @@ -53,6 +53,7 @@ class GameHistoryScreen extends ConsumerWidget { semanticsLabel: context.l10n.filterGames, onPressed: () => showAdaptiveBottomSheet( context: context, + isScrollControlled: true, builder: (_) => _FilterGames( filter: ref.read(gameFilterProvider(filter: gameFilter)), user: user, @@ -250,75 +251,48 @@ class _FilterGamesState extends ConsumerState<_FilterGames> { filter = widget.filter; } + static const gamePerfs = [ + Perf.ultraBullet, + Perf.bullet, + Perf.blitz, + Perf.rapid, + Perf.classical, + Perf.correspondence, + Perf.chess960, + Perf.antichess, + Perf.kingOfTheHill, + Perf.threeCheck, + Perf.atomic, + Perf.horde, + Perf.racingKings, + Perf.crazyhouse, + ]; + static const filterGroupSpace = SizedBox(height: 10.0); + @override Widget build(BuildContext context) { - const gamePerfs = [ - Perf.ultraBullet, - Perf.bullet, - Perf.blitz, - Perf.rapid, - Perf.classical, - Perf.correspondence, - Perf.chess960, - Perf.antichess, - Perf.kingOfTheHill, - Perf.threeCheck, - Perf.atomic, - Perf.horde, - Perf.racingKings, - Perf.crazyhouse, - ]; - const filterGroupSpace = SizedBox(height: 10.0); - final session = ref.read(authSessionProvider); final userId = widget.user?.id ?? session?.user.id; - List availablePerfs(User user) { - final perfs = gamePerfs.where((perf) { - final p = user.perfs[perf]; - return p != null && p.numberOfGamesOrRuns > 0; - }).toList(growable: false); - perfs.sort( - (p1, p2) => user.perfs[p2]!.numberOfGamesOrRuns - .compareTo(user.perfs[p1]!.numberOfGamesOrRuns), - ); - return perfs; - } - - Widget perfFilter(List choices) => _Filter( - filterName: context.l10n.variant, - filterType: FilterType.multipleChoice, - choices: choices, - choiceSelected: (choice) => filter.perfs.contains(choice), - choiceLabel: (t) => t.shortTitle, - onSelected: (value, selected) => setState( - () { - filter = filter.copyWith( - perfs: selected - ? filter.perfs.add(value) - : filter.perfs.remove(value), - ); - }, - ), - ); + final Widget filters = userId != null + ? ref.watch(userProvider(id: userId)).when( + data: (user) => perfFilter(availablePerfs(user)), + loading: () => const Center( + child: CircularProgressIndicator.adaptive(), + ), + error: (_, __) => perfFilter(gamePerfs), + ) + : perfFilter(gamePerfs); return SafeArea( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, children: [ + filters, const SizedBox(height: 12.0), - if (userId != null) - ref.watch(userProvider(id: userId)).when( - data: (user) => perfFilter(availablePerfs(user)), - loading: () => const Center( - child: CircularProgressIndicator.adaptive(), - ), - error: (_, __) => perfFilter(gamePerfs), - ) - else - perfFilter(gamePerfs), const PlatformDivider(thickness: 1, indent: 0), filterGroupSpace, _Filter( @@ -356,6 +330,35 @@ class _FilterGamesState extends ConsumerState<_FilterGames> { ), ); } + + List availablePerfs(User user) { + final perfs = gamePerfs.where((perf) { + final p = user.perfs[perf]; + return p != null && p.numberOfGamesOrRuns > 0; + }).toList(growable: false); + perfs.sort( + (p1, p2) => user.perfs[p2]!.numberOfGamesOrRuns + .compareTo(user.perfs[p1]!.numberOfGamesOrRuns), + ); + return perfs; + } + + Widget perfFilter(List choices) => _Filter( + filterName: context.l10n.variant, + filterType: FilterType.multipleChoice, + choices: choices, + choiceSelected: (choice) => filter.perfs.contains(choice), + choiceLabel: (t) => t.shortTitle, + onSelected: (value, selected) => setState( + () { + filter = filter.copyWith( + perfs: selected + ? filter.perfs.add(value) + : filter.perfs.remove(value), + ); + }, + ), + ); } enum FilterType {