From 7fb0301ab6f662238008840ffefc6ae0c98a263a Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Fri, 6 Dec 2024 19:42:17 +0100 Subject: [PATCH] Remove useless SafeArea to fix cupertino headers --- lib/src/view/puzzle/dashboard_screen.dart | 11 +- lib/src/view/puzzle/opening_screen.dart | 69 +- lib/src/view/puzzle/puzzle_themes_screen.dart | 81 +- .../settings/account_preferences_screen.dart | 731 +++++++++--------- .../view/settings/board_settings_screen.dart | 404 +++++----- .../view/settings/sound_settings_screen.dart | 52 +- lib/src/view/settings/theme_screen.dart | 270 ++++--- lib/src/view/study/study_list_screen.dart | 2 +- lib/src/view/user/game_history_screen.dart | 104 ++- lib/src/view/user/perf_stats_screen.dart | 456 ++++++----- lib/src/view/user/player_screen.dart | 20 +- 11 files changed, 1084 insertions(+), 1116 deletions(-) diff --git a/lib/src/view/puzzle/dashboard_screen.dart b/lib/src/view/puzzle/dashboard_screen.dart index 705c13a762..7cb172be93 100644 --- a/lib/src/view/puzzle/dashboard_screen.dart +++ b/lib/src/view/puzzle/dashboard_screen.dart @@ -39,13 +39,10 @@ class _Body extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - return SafeArea( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - PuzzleDashboardWidget(), - ], - ), + return ListView( + children: [ + PuzzleDashboardWidget(), + ], ); } } diff --git a/lib/src/view/puzzle/opening_screen.dart b/lib/src/view/puzzle/opening_screen.dart index 62166de177..b2386aab32 100644 --- a/lib/src/view/puzzle/opening_screen.dart +++ b/lib/src/view/puzzle/opening_screen.dart @@ -53,40 +53,41 @@ class _Body extends ConsumerWidget { : null; final openings = ref.watch(_openingsProvider); - return SafeArea( - child: openings.when( - data: (data) { - final (isOnline, savedOpenings, onlineOpenings) = data; - if (isOnline && onlineOpenings != null) { - return ListView( - children: [ - for (final openingFamily in onlineOpenings) - _OpeningFamily( - openingFamily: openingFamily, - titleStyle: titleStyle, - ), - ], - ); - } else { - return ListSection( - children: [ - for (final openingKey in savedOpenings.keys) - _OpeningTile( - name: openingKey.replaceAll('_', ' '), - openingKey: openingKey, - count: savedOpenings[openingKey]!, - titleStyle: titleStyle, - ), - ], - ); - } - }, - error: (error, stack) { - return const Center(child: Text('Could not load openings.')); - }, - loading: () => - const Center(child: CircularProgressIndicator.adaptive()), - ), + return openings.when( + data: (data) { + final (isOnline, savedOpenings, onlineOpenings) = data; + if (isOnline && onlineOpenings != null) { + return ListView( + children: [ + for (final openingFamily in onlineOpenings) + _OpeningFamily( + openingFamily: openingFamily, + titleStyle: titleStyle, + ), + ], + ); + } else { + return ListView( + children: [ + ListSection( + children: [ + for (final openingKey in savedOpenings.keys) + _OpeningTile( + name: openingKey.replaceAll('_', ' '), + openingKey: openingKey, + count: savedOpenings[openingKey]!, + titleStyle: titleStyle, + ), + ], + ), + ], + ); + } + }, + error: (error, stack) { + return const Center(child: Text('Could not load openings.')); + }, + loading: () => const Center(child: CircularProgressIndicator.adaptive()), ); } } diff --git a/lib/src/view/puzzle/puzzle_themes_screen.dart b/lib/src/view/puzzle/puzzle_themes_screen.dart index e29e793f05..5f080eae17 100644 --- a/lib/src/view/puzzle/puzzle_themes_screen.dart +++ b/lib/src/view/puzzle/puzzle_themes_screen.dart @@ -67,51 +67,48 @@ class _Body extends ConsumerWidget { ? CupertinoColors.secondaryLabel.resolveFrom(context) : null; - return SafeArea( - child: themes.when( - data: (data) { - final (hasConnectivity, savedThemes, onlineThemes, hasSavedOpenings) = - data; + return themes.when( + data: (data) { + final (hasConnectivity, savedThemes, onlineThemes, hasSavedOpenings) = + data; - final openingsAvailable = hasConnectivity || hasSavedOpenings; - return ListView( - children: [ - Theme( - data: Theme.of(context) - .copyWith(dividerColor: Colors.transparent), - child: Opacity( - opacity: openingsAvailable ? 1 : 0.5, - child: ExpansionTile( - iconColor: expansionTileColor, - collapsedIconColor: expansionTileColor, - title: Text(context.l10n.puzzleByOpenings), - trailing: const Icon(Icons.keyboard_arrow_right), - onExpansionChanged: openingsAvailable - ? (expanded) { - pushPlatformRoute( - context, - builder: (ctx) => const OpeningThemeScreen(), - ); - } - : null, - ), + final openingsAvailable = hasConnectivity || hasSavedOpenings; + return ListView( + children: [ + Theme( + data: + Theme.of(context).copyWith(dividerColor: Colors.transparent), + child: Opacity( + opacity: openingsAvailable ? 1 : 0.5, + child: ExpansionTile( + iconColor: expansionTileColor, + collapsedIconColor: expansionTileColor, + title: Text(context.l10n.puzzleByOpenings), + trailing: const Icon(Icons.keyboard_arrow_right), + onExpansionChanged: openingsAvailable + ? (expanded) { + pushPlatformRoute( + context, + builder: (ctx) => const OpeningThemeScreen(), + ); + } + : null, ), ), - for (final category in list) - _Category( - hasConnectivity: hasConnectivity, - category: category, - onlineThemes: onlineThemes, - savedThemes: savedThemes, - ), - ], - ); - }, - loading: () => - const Center(child: CircularProgressIndicator.adaptive()), - error: (error, stack) => - const Center(child: Text('Could not load themes.')), - ), + ), + for (final category in list) + _Category( + hasConnectivity: hasConnectivity, + category: category, + onlineThemes: onlineThemes, + savedThemes: savedThemes, + ), + ], + ); + }, + loading: () => const Center(child: CircularProgressIndicator.adaptive()), + error: (error, stack) => + const Center(child: Text('Could not load themes.')), ); } } diff --git a/lib/src/view/settings/account_preferences_screen.dart b/lib/src/view/settings/account_preferences_screen.dart index ac283ef583..f6797646d3 100644 --- a/lib/src/view/settings/account_preferences_screen.dart +++ b/lib/src/view/settings/account_preferences_screen.dart @@ -47,395 +47,384 @@ class _AccountPreferencesScreenState ); } - return SafeArea( - child: ListView( - children: [ - ListSection( - header: SettingsSectionTitle(context.l10n.preferencesDisplay), - hasLeading: false, - children: [ - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesZenMode, - ), - settingsValue: data.zenMode.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: Zen.values, - selectedItem: data.zenMode, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (Zen? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setZen(value ?? data.zenMode), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n.preferencesZenMode, - builder: (context) => const ZenSettingsScreen(), - ); - } - }, + return ListView( + children: [ + ListSection( + header: SettingsSectionTitle(context.l10n.preferencesDisplay), + hasLeading: false, + children: [ + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesZenMode, ), - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesPgnPieceNotation, - ), - settingsValue: data.pieceNotation.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: PieceNotation.values, - selectedItem: data.pieceNotation, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (PieceNotation? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setPieceNotation( - value ?? data.pieceNotation, - ), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n.preferencesPgnPieceNotation, - builder: (context) => - const PieceNotationSettingsScreen(), - ); - } - }, + settingsValue: data.zenMode.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: Zen.values, + selectedItem: data.zenMode, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (Zen? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setZen(value ?? data.zenMode), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n.preferencesZenMode, + builder: (context) => const ZenSettingsScreen(), + ); + } + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesPgnPieceNotation, ), - SwitchSettingTile( - title: Text(context.l10n.preferencesShowPlayerRatings), - subtitle: Text( - context.l10n.preferencesExplainShowPlayerRatings, - maxLines: 5, - textAlign: TextAlign.justify, - ), - value: data.showRatings.value, - onChanged: isLoading - ? null - : (value) { - _setPref( - () => ref - .read(accountPreferencesProvider.notifier) - .setShowRatings(BooleanPref(value)), - ); - }, + settingsValue: data.pieceNotation.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: PieceNotation.values, + selectedItem: data.pieceNotation, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (PieceNotation? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setPieceNotation( + value ?? data.pieceNotation, + ), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n.preferencesPgnPieceNotation, + builder: (context) => + const PieceNotationSettingsScreen(), + ); + } + }, + ), + SwitchSettingTile( + title: Text(context.l10n.preferencesShowPlayerRatings), + subtitle: Text( + context.l10n.preferencesExplainShowPlayerRatings, + maxLines: 5, + textAlign: TextAlign.justify, ), - ], - ), - ListSection( - header: - SettingsSectionTitle(context.l10n.preferencesGameBehavior), - hasLeading: false, - children: [ - SwitchSettingTile( - title: Text( - context.l10n.preferencesPremovesPlayingDuringOpponentTurn, - ), - value: data.premove.value, - onChanged: isLoading - ? null - : (value) { - _setPref( - () => ref - .read(accountPreferencesProvider.notifier) - .setPremove(BooleanPref(value)), - ); - }, + value: data.showRatings.value, + onChanged: isLoading + ? null + : (value) { + _setPref( + () => ref + .read(accountPreferencesProvider.notifier) + .setShowRatings(BooleanPref(value)), + ); + }, + ), + ], + ), + ListSection( + header: + SettingsSectionTitle(context.l10n.preferencesGameBehavior), + hasLeading: false, + children: [ + SwitchSettingTile( + title: Text( + context.l10n.preferencesPremovesPlayingDuringOpponentTurn, ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesConfirmResignationAndDrawOffers, - ), - value: data.confirmResign.value, - onChanged: isLoading - ? null - : (value) { - _setPref( - () => ref - .read(accountPreferencesProvider.notifier) - .setConfirmResign(BooleanPref(value)), - ); - }, + value: data.premove.value, + onChanged: isLoading + ? null + : (value) { + _setPref( + () => ref + .read(accountPreferencesProvider.notifier) + .setPremove(BooleanPref(value)), + ); + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesConfirmResignationAndDrawOffers, ), - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesTakebacksWithOpponentApproval, - ), - settingsValue: data.takeback.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: Takeback.values, - selectedItem: data.takeback, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (Takeback? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setTakeback(value ?? data.takeback), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context - .l10n.preferencesTakebacksWithOpponentApproval, - builder: (context) => const TakebackSettingsScreen(), - ); - } - }, + value: data.confirmResign.value, + onChanged: isLoading + ? null + : (value) { + _setPref( + () => ref + .read(accountPreferencesProvider.notifier) + .setConfirmResign(BooleanPref(value)), + ); + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesTakebacksWithOpponentApproval, ), - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesPromoteToQueenAutomatically, - ), - settingsValue: data.autoQueen.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: AutoQueen.values, - selectedItem: data.autoQueen, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (AutoQueen? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setAutoQueen(value ?? data.autoQueen), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context - .l10n.preferencesPromoteToQueenAutomatically, - builder: (context) => const AutoQueenSettingsScreen(), - ); - } - }, + settingsValue: data.takeback.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: Takeback.values, + selectedItem: data.takeback, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (Takeback? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setTakeback(value ?? data.takeback), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context + .l10n.preferencesTakebacksWithOpponentApproval, + builder: (context) => const TakebackSettingsScreen(), + ); + } + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesPromoteToQueenAutomatically, ), - SettingsListTile( - settingsLabel: Text( - context.l10n - .preferencesClaimDrawOnThreefoldRepetitionAutomatically, - ), - settingsValue: data.autoThreefold.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: AutoThreefold.values, - selectedItem: data.autoThreefold, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (AutoThreefold? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setAutoThreefold( - value ?? data.autoThreefold, - ), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n - .preferencesClaimDrawOnThreefoldRepetitionAutomatically, - builder: (context) => - const AutoThreefoldSettingsScreen(), + settingsValue: data.autoQueen.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: AutoQueen.values, + selectedItem: data.autoQueen, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (AutoQueen? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setAutoQueen(value ?? data.autoQueen), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: + context.l10n.preferencesPromoteToQueenAutomatically, + builder: (context) => const AutoQueenSettingsScreen(), + ); + } + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n + .preferencesClaimDrawOnThreefoldRepetitionAutomatically, + ), + settingsValue: data.autoThreefold.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: AutoThreefold.values, + selectedItem: data.autoThreefold, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (AutoThreefold? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setAutoThreefold( + value ?? data.autoThreefold, + ), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n + .preferencesClaimDrawOnThreefoldRepetitionAutomatically, + builder: (context) => + const AutoThreefoldSettingsScreen(), + ); + } + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesMoveConfirmation, + ), + settingsValue: data.submitMove.label(context), + showCupertinoTrailingValue: false, + onTap: () { + showMultipleChoicesPicker( + context, + choices: SubmitMoveChoice.values, + selectedItems: data.submitMove.choices, + labelBuilder: (t) => Text(t.label(context)), + ).then((value) { + if (value != null) { + _setPref( + () => ref + .read(accountPreferencesProvider.notifier) + .setSubmitMove(SubmitMove(value)), ); } - }, + }); + }, + explanation: context + .l10n.preferencesExplainCanThenBeTemporarilyDisabled, + ), + ], + ), + ListSection( + header: SettingsSectionTitle(context.l10n.preferencesChessClock), + hasLeading: false, + children: [ + SettingsListTile( + settingsLabel: Text( + context.l10n.preferencesGiveMoreTime, ), - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesMoveConfirmation, - ), - settingsValue: data.submitMove.label(context), - showCupertinoTrailingValue: false, - onTap: () { - showMultipleChoicesPicker( + settingsValue: data.moretime.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( context, - choices: SubmitMoveChoice.values, - selectedItems: data.submitMove.choices, + choices: Moretime.values, + selectedItem: data.moretime, labelBuilder: (t) => Text(t.label(context)), - ).then((value) { - if (value != null) { + onSelectedItemChanged: isLoading + ? null + : (Moretime? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setMoretime(value ?? data.moretime), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n.preferencesGiveMoreTime, + builder: (context) => const MoretimeSettingsScreen(), + ); + } + }, + ), + SwitchSettingTile( + title: + Text(context.l10n.preferencesSoundWhenTimeGetsCritical), + value: data.clockSound.value, + onChanged: isLoading + ? null + : (value) { _setPref( () => ref .read(accountPreferencesProvider.notifier) - .setSubmitMove(SubmitMove(value)), + .setClockSound(BooleanPref(value)), ); - } - }); - }, - explanation: context - .l10n.preferencesExplainCanThenBeTemporarilyDisabled, - ), - ], - ), - ListSection( - header: - SettingsSectionTitle(context.l10n.preferencesChessClock), - hasLeading: false, - children: [ - SettingsListTile( - settingsLabel: Text( - context.l10n.preferencesGiveMoreTime, - ), - settingsValue: data.moretime.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: Moretime.values, - selectedItem: data.moretime, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (Moretime? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setMoretime(value ?? data.moretime), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n.preferencesGiveMoreTime, - builder: (context) => const MoretimeSettingsScreen(), - ); - } - }, - ), - SwitchSettingTile( - title: - Text(context.l10n.preferencesSoundWhenTimeGetsCritical), - value: data.clockSound.value, - onChanged: isLoading - ? null - : (value) { - _setPref( - () => ref - .read(accountPreferencesProvider.notifier) - .setClockSound(BooleanPref(value)), - ); - }, - ), - ], - ), - ListSection( - header: SettingsSectionTitle(context.l10n.preferencesPrivacy), - hasLeading: false, - children: [ - SwitchSettingTile( - title: Text( - context.l10n.letOtherPlayersFollowYou, - ), - value: data.follow.value, - onChanged: isLoading - ? null - : (value) { - _setPref( - () => ref - .read(accountPreferencesProvider.notifier) - .setFollow(BooleanPref(value)), - ); - }, + }, + ), + ], + ), + ListSection( + header: SettingsSectionTitle(context.l10n.preferencesPrivacy), + hasLeading: false, + children: [ + SwitchSettingTile( + title: Text( + context.l10n.letOtherPlayersFollowYou, ), - SettingsListTile( - settingsLabel: Text( - context.l10n.letOtherPlayersChallengeYou, - ), - settingsValue: data.challenge.label(context), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == - TargetPlatform.android) { - showChoicePicker( - context, - choices: Challenge.values, - selectedItem: data.challenge, - labelBuilder: (t) => Text(t.label(context)), - onSelectedItemChanged: isLoading - ? null - : (Challenge? value) { - _setPref( - () => ref - .read( - accountPreferencesProvider.notifier, - ) - .setChallenge(value ?? data.challenge), - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n.letOtherPlayersChallengeYou, - builder: (context) => - const _ChallengeSettingsScreen(), - ); - } - }, + value: data.follow.value, + onChanged: isLoading + ? null + : (value) { + _setPref( + () => ref + .read(accountPreferencesProvider.notifier) + .setFollow(BooleanPref(value)), + ); + }, + ), + SettingsListTile( + settingsLabel: Text( + context.l10n.letOtherPlayersChallengeYou, ), - ], - ), - ], - ), + settingsValue: data.challenge.label(context), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: Challenge.values, + selectedItem: data.challenge, + labelBuilder: (t) => Text(t.label(context)), + onSelectedItemChanged: isLoading + ? null + : (Challenge? value) { + _setPref( + () => ref + .read( + accountPreferencesProvider.notifier, + ) + .setChallenge(value ?? data.challenge), + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n.letOtherPlayersChallengeYou, + builder: (context) => const _ChallengeSettingsScreen(), + ); + } + }, + ), + ], + ), + ], ); }, loading: () => const Center(child: CircularProgressIndicator()), diff --git a/lib/src/view/settings/board_settings_screen.dart b/lib/src/view/settings/board_settings_screen.dart index 799b082214..d031528993 100644 --- a/lib/src/view/settings/board_settings_screen.dart +++ b/lib/src/view/settings/board_settings_screen.dart @@ -48,218 +48,214 @@ class _Body extends ConsumerWidget { final androidVersionAsync = ref.watch(androidVersionProvider); - return SafeArea( - child: ListView( - children: [ - ListSection( - header: SettingsSectionTitle(context.l10n.preferencesGameBehavior), - hasLeading: false, - showDivider: false, - children: [ - SettingsListTile( - settingsLabel: Text(context.l10n.preferencesHowDoYouMovePieces), - settingsValue: - pieceShiftMethodl10n(context, boardPrefs.pieceShiftMethod), - showCupertinoTrailingValue: false, - onTap: () { - if (Theme.of(context).platform == TargetPlatform.android) { - showChoicePicker( - context, - choices: PieceShiftMethod.values, - selectedItem: boardPrefs.pieceShiftMethod, - labelBuilder: (t) => - Text(pieceShiftMethodl10n(context, t)), - onSelectedItemChanged: (PieceShiftMethod? value) { - ref - .read(boardPreferencesProvider.notifier) - .setPieceShiftMethod( - value ?? PieceShiftMethod.either, - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: context.l10n.preferencesHowDoYouMovePieces, - builder: (context) => - const PieceShiftMethodSettingsScreen(), - ); - } - }, - ), - SwitchSettingTile( - title: Text(context.l10n.mobilePrefMagnifyDraggedPiece), - value: boardPrefs.magnifyDraggedPiece, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleMagnifyDraggedPiece(); - }, - ), - SettingsListTile( - // TODO translate - settingsLabel: const Text('Drag target'), - explanation: - // TODO translate - 'How the target square is highlighted when dragging a piece.', - settingsValue: dragTargetKindLabel(boardPrefs.dragTargetKind), - onTap: () { - if (Theme.of(context).platform == TargetPlatform.android) { - showChoicePicker( - context, - choices: DragTargetKind.values, - selectedItem: boardPrefs.dragTargetKind, - labelBuilder: (t) => Text(dragTargetKindLabel(t)), - onSelectedItemChanged: (DragTargetKind? value) { - ref - .read(boardPreferencesProvider.notifier) - .setDragTargetKind( - value ?? DragTargetKind.circle, - ); - }, - ); - } else { - pushPlatformRoute( - context, - title: 'Dragged piece target', - builder: (context) => - const DragTargetKindSettingsScreen(), - ); - } - }, - ), - SwitchSettingTile( - // TODO translate - title: const Text('Touch feedback'), - value: boardPrefs.hapticFeedback, - subtitle: const Text( + return ListView( + children: [ + ListSection( + header: SettingsSectionTitle(context.l10n.preferencesGameBehavior), + hasLeading: false, + showDivider: false, + children: [ + SettingsListTile( + settingsLabel: Text(context.l10n.preferencesHowDoYouMovePieces), + settingsValue: + pieceShiftMethodl10n(context, boardPrefs.pieceShiftMethod), + showCupertinoTrailingValue: false, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: PieceShiftMethod.values, + selectedItem: boardPrefs.pieceShiftMethod, + labelBuilder: (t) => Text(pieceShiftMethodl10n(context, t)), + onSelectedItemChanged: (PieceShiftMethod? value) { + ref + .read(boardPreferencesProvider.notifier) + .setPieceShiftMethod( + value ?? PieceShiftMethod.either, + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: context.l10n.preferencesHowDoYouMovePieces, + builder: (context) => + const PieceShiftMethodSettingsScreen(), + ); + } + }, + ), + SwitchSettingTile( + title: Text(context.l10n.mobilePrefMagnifyDraggedPiece), + value: boardPrefs.magnifyDraggedPiece, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleMagnifyDraggedPiece(); + }, + ), + SettingsListTile( + // TODO translate + settingsLabel: const Text('Drag target'), + explanation: // TODO translate - 'Vibrate when moving pieces or capturing them.', - maxLines: 5, - textAlign: TextAlign.justify, - ), - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleHapticFeedback(); - }, + 'How the target square is highlighted when dragging a piece.', + settingsValue: dragTargetKindLabel(boardPrefs.dragTargetKind), + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: DragTargetKind.values, + selectedItem: boardPrefs.dragTargetKind, + labelBuilder: (t) => Text(dragTargetKindLabel(t)), + onSelectedItemChanged: (DragTargetKind? value) { + ref + .read(boardPreferencesProvider.notifier) + .setDragTargetKind( + value ?? DragTargetKind.circle, + ); + }, + ); + } else { + pushPlatformRoute( + context, + title: 'Dragged piece target', + builder: (context) => const DragTargetKindSettingsScreen(), + ); + } + }, + ), + SwitchSettingTile( + // TODO translate + title: const Text('Touch feedback'), + value: boardPrefs.hapticFeedback, + subtitle: const Text( + // TODO translate + 'Vibrate when moving pieces or capturing them.', + maxLines: 5, + textAlign: TextAlign.justify, ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesPieceAnimation, - ), - value: boardPrefs.pieceAnimation, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .togglePieceAnimation(); - }, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleHapticFeedback(); + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesPieceAnimation, ), - SwitchSettingTile( - // TODO: Add l10n - title: const Text('Shape drawing'), - subtitle: const Text( - // TODO: translate - 'Draw shapes using two fingers: maintain one finger on an empty square and drag another finger to draw a shape.', - maxLines: 5, - textAlign: TextAlign.justify, - ), - value: boardPrefs.enableShapeDrawings, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleEnableShapeDrawings(); - }, + value: boardPrefs.pieceAnimation, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .togglePieceAnimation(); + }, + ), + SwitchSettingTile( + // TODO: Add l10n + title: const Text('Shape drawing'), + subtitle: const Text( + // TODO: translate + 'Draw shapes using two fingers: maintain one finger on an empty square and drag another finger to draw a shape.', + maxLines: 5, + textAlign: TextAlign.justify, ), - ], - ), - ListSection( - header: SettingsSectionTitle(context.l10n.preferencesDisplay), - hasLeading: false, - showDivider: false, - children: [ - if (Theme.of(context).platform == TargetPlatform.android && - !isTabletOrLarger(context)) - androidVersionAsync.maybeWhen( - data: (version) => version != null && version.sdkInt >= 29 - ? SwitchSettingTile( - title: Text(context.l10n.mobileSettingsImmersiveMode), - subtitle: Text( - context.l10n.mobileSettingsImmersiveModeSubtitle, - textAlign: TextAlign.justify, - maxLines: 5, - ), - value: boardPrefs.immersiveModeWhilePlaying ?? false, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleImmersiveModeWhilePlaying(); - }, - ) - : const SizedBox.shrink(), - orElse: () => const SizedBox.shrink(), - ), - SettingsListTile( - //TODO Add l10n - settingsLabel: const Text('Clock position'), - settingsValue: boardPrefs.clockPosition.label, - onTap: () { - if (Theme.of(context).platform == TargetPlatform.android) { - showChoicePicker( - context, - choices: ClockPosition.values, - selectedItem: boardPrefs.clockPosition, - labelBuilder: (t) => Text(t.label), - onSelectedItemChanged: (ClockPosition? value) => ref - .read(boardPreferencesProvider.notifier) - .setClockPosition(value ?? ClockPosition.right), - ); - } else { - pushPlatformRoute( - context, - title: 'Clock position', - builder: (context) => const BoardClockPositionScreen(), - ); - } - }, + value: boardPrefs.enableShapeDrawings, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleEnableShapeDrawings(); + }, + ), + ], + ), + ListSection( + header: SettingsSectionTitle(context.l10n.preferencesDisplay), + hasLeading: false, + showDivider: false, + children: [ + if (Theme.of(context).platform == TargetPlatform.android && + !isTabletOrLarger(context)) + androidVersionAsync.maybeWhen( + data: (version) => version != null && version.sdkInt >= 29 + ? SwitchSettingTile( + title: Text(context.l10n.mobileSettingsImmersiveMode), + subtitle: Text( + context.l10n.mobileSettingsImmersiveModeSubtitle, + textAlign: TextAlign.justify, + maxLines: 5, + ), + value: boardPrefs.immersiveModeWhilePlaying ?? false, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleImmersiveModeWhilePlaying(); + }, + ) + : const SizedBox.shrink(), + orElse: () => const SizedBox.shrink(), ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesPieceDestinations, - ), - value: boardPrefs.showLegalMoves, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleShowLegalMoves(); - }, + SettingsListTile( + //TODO Add l10n + settingsLabel: const Text('Clock position'), + settingsValue: boardPrefs.clockPosition.label, + onTap: () { + if (Theme.of(context).platform == TargetPlatform.android) { + showChoicePicker( + context, + choices: ClockPosition.values, + selectedItem: boardPrefs.clockPosition, + labelBuilder: (t) => Text(t.label), + onSelectedItemChanged: (ClockPosition? value) => ref + .read(boardPreferencesProvider.notifier) + .setClockPosition(value ?? ClockPosition.right), + ); + } else { + pushPlatformRoute( + context, + title: 'Clock position', + builder: (context) => const BoardClockPositionScreen(), + ); + } + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesPieceDestinations, ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesBoardHighlights, - ), - value: boardPrefs.boardHighlights, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleBoardHighlights(); - }, + value: boardPrefs.showLegalMoves, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleShowLegalMoves(); + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesBoardHighlights, ), - SwitchSettingTile( - title: Text( - context.l10n.preferencesMaterialDifference, - ), - value: boardPrefs.showMaterialDifference, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleShowMaterialDifference(); - }, + value: boardPrefs.boardHighlights, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleBoardHighlights(); + }, + ), + SwitchSettingTile( + title: Text( + context.l10n.preferencesMaterialDifference, ), - ], - ), - ], - ), + value: boardPrefs.showMaterialDifference, + onChanged: (value) { + ref + .read(boardPreferencesProvider.notifier) + .toggleShowMaterialDifference(); + }, + ), + ], + ), + ], ); } } diff --git a/lib/src/view/settings/sound_settings_screen.dart b/lib/src/view/settings/sound_settings_screen.dart index e4d3fdee62..75010c06c4 100644 --- a/lib/src/view/settings/sound_settings_screen.dart +++ b/lib/src/view/settings/sound_settings_screen.dart @@ -70,33 +70,31 @@ class _Body extends ConsumerWidget { ); } - return SafeArea( - child: ListView( - children: [ - ListSection( - children: [ - SliderSettingsTile( - icon: const Icon(Icons.volume_up), - value: generalPrefs.masterVolume, - values: kMasterVolumeValues, - onChangeEnd: (value) { - ref - .read(generalPreferencesProvider.notifier) - .setMasterVolume(value); - }, - labelBuilder: volumeLabel, - ), - ], - ), - ChoicePicker( - notchedTile: true, - choices: SoundTheme.values, - selectedItem: generalPrefs.soundTheme, - titleBuilder: (t) => Text(soundThemeL10n(context, t)), - onSelectedItemChanged: onChanged, - ), - ], - ), + return ListView( + children: [ + ListSection( + children: [ + SliderSettingsTile( + icon: const Icon(Icons.volume_up), + value: generalPrefs.masterVolume, + values: kMasterVolumeValues, + onChangeEnd: (value) { + ref + .read(generalPreferencesProvider.notifier) + .setMasterVolume(value); + }, + labelBuilder: volumeLabel, + ), + ], + ), + ChoicePicker( + notchedTile: true, + choices: SoundTheme.values, + selectedItem: generalPrefs.soundTheme, + titleBuilder: (t) => Text(soundThemeL10n(context, t)), + onSelectedItemChanged: onChanged, + ), + ], ); } } diff --git a/lib/src/view/settings/theme_screen.dart b/lib/src/view/settings/theme_screen.dart index a4de7ca25d..2e16832dc7 100644 --- a/lib/src/view/settings/theme_screen.dart +++ b/lib/src/view/settings/theme_screen.dart @@ -51,150 +51,146 @@ class _Body extends ConsumerWidget { const horizontalPadding = 16.0; - return SafeArea( - child: ListView( - children: [ - LayoutBuilder( - builder: (context, constraints) { - final double boardSize = math.min( - 400, - constraints.biggest.shortestSide - horizontalPadding * 2, - ); - return Padding( - padding: const EdgeInsets.symmetric( - horizontal: horizontalPadding, - vertical: 16, - ), - child: Center( - child: Chessboard.fixed( - size: boardSize, - orientation: Side.white, - lastMove: const NormalMove(from: Square.e2, to: Square.e4), - fen: - 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1', - shapes: { - Circle( - color: boardPrefs.shapeColor.color, - orig: Square.fromName('b8'), - ), - Arrow( - color: boardPrefs.shapeColor.color, - orig: Square.fromName('b8'), - dest: Square.fromName('c6'), + return ListView( + children: [ + LayoutBuilder( + builder: (context, constraints) { + final double boardSize = math.min( + 400, + constraints.biggest.shortestSide - horizontalPadding * 2, + ); + return Padding( + padding: const EdgeInsets.symmetric( + horizontal: horizontalPadding, + vertical: 16, + ), + child: Center( + child: Chessboard.fixed( + size: boardSize, + orientation: Side.white, + lastMove: const NormalMove(from: Square.e2, to: Square.e4), + fen: + 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1', + shapes: { + Circle( + color: boardPrefs.shapeColor.color, + orig: Square.fromName('b8'), + ), + Arrow( + color: boardPrefs.shapeColor.color, + orig: Square.fromName('b8'), + dest: Square.fromName('c6'), + ), + }.lock, + settings: boardPrefs.toBoardSettings().copyWith( + borderRadius: + const BorderRadius.all(Radius.circular(4.0)), + boxShadow: boardShadows, ), - }.lock, - settings: boardPrefs.toBoardSettings().copyWith( - borderRadius: - const BorderRadius.all(Radius.circular(4.0)), - boxShadow: boardShadows, - ), - ), - ), - ); - }, - ), - ListSection( - hasLeading: true, - children: [ - if (Theme.of(context).platform == TargetPlatform.android) - androidVersionAsync.maybeWhen( - data: (version) => version != null && version.sdkInt >= 31 - ? SwitchSettingTile( - leading: const Icon(Icons.colorize_outlined), - title: Text(context.l10n.mobileSystemColors), - value: generalPrefs.systemColors, - onChanged: (value) { - ref - .read(generalPreferencesProvider.notifier) - .toggleSystemColors(); - }, - ) - : const SizedBox.shrink(), - orElse: () => const SizedBox.shrink(), ), - SettingsListTile( - icon: const Icon(LichessIcons.chess_board), - settingsLabel: Text(context.l10n.board), - settingsValue: boardPrefs.boardTheme.label, - onTap: () { - pushPlatformRoute( - context, - title: context.l10n.board, - builder: (context) => const BoardThemeScreen(), - ); - }, ), - SettingsListTile( - icon: const Icon(LichessIcons.chess_pawn), - settingsLabel: Text(context.l10n.pieceSet), - settingsValue: boardPrefs.pieceSet.label, - onTap: () { - pushPlatformRoute( - context, - title: context.l10n.pieceSet, - builder: (context) => const PieceSetScreen(), - ); - }, + ); + }, + ), + ListSection( + hasLeading: true, + children: [ + if (Theme.of(context).platform == TargetPlatform.android) + androidVersionAsync.maybeWhen( + data: (version) => version != null && version.sdkInt >= 31 + ? SwitchSettingTile( + leading: const Icon(Icons.colorize_outlined), + title: Text(context.l10n.mobileSystemColors), + value: generalPrefs.systemColors, + onChanged: (value) { + ref + .read(generalPreferencesProvider.notifier) + .toggleSystemColors(); + }, + ) + : const SizedBox.shrink(), + orElse: () => const SizedBox.shrink(), ), - SettingsListTile( - icon: const Icon(LichessIcons.arrow_full_upperright), - settingsLabel: const Text('Shape color'), - settingsValue: shapeColorL10n(context, boardPrefs.shapeColor), - onTap: () { - showChoicePicker( - context, - choices: ShapeColor.values, - selectedItem: boardPrefs.shapeColor, - labelBuilder: (t) => Text.rich( - TextSpan( - children: [ - TextSpan( - text: shapeColorL10n(context, t), - ), - const TextSpan(text: ' '), - WidgetSpan( - child: Container( - width: 15, - height: 15, - color: t.color, - ), + SettingsListTile( + icon: const Icon(LichessIcons.chess_board), + settingsLabel: Text(context.l10n.board), + settingsValue: boardPrefs.boardTheme.label, + onTap: () { + pushPlatformRoute( + context, + title: context.l10n.board, + builder: (context) => const BoardThemeScreen(), + ); + }, + ), + SettingsListTile( + icon: const Icon(LichessIcons.chess_pawn), + settingsLabel: Text(context.l10n.pieceSet), + settingsValue: boardPrefs.pieceSet.label, + onTap: () { + pushPlatformRoute( + context, + title: context.l10n.pieceSet, + builder: (context) => const PieceSetScreen(), + ); + }, + ), + SettingsListTile( + icon: const Icon(LichessIcons.arrow_full_upperright), + settingsLabel: const Text('Shape color'), + settingsValue: shapeColorL10n(context, boardPrefs.shapeColor), + onTap: () { + showChoicePicker( + context, + choices: ShapeColor.values, + selectedItem: boardPrefs.shapeColor, + labelBuilder: (t) => Text.rich( + TextSpan( + children: [ + TextSpan( + text: shapeColorL10n(context, t), + ), + const TextSpan(text: ' '), + WidgetSpan( + child: Container( + width: 15, + height: 15, + color: t.color, ), - ], - ), + ), + ], ), - onSelectedItemChanged: (ShapeColor? value) { - ref - .read(boardPreferencesProvider.notifier) - .setShapeColor(value ?? ShapeColor.green); - }, - ); - }, - ), - SwitchSettingTile( - leading: const Icon(Icons.location_on), - title: Text( - context.l10n.preferencesBoardCoordinates, - ), - value: boardPrefs.coordinates, - onChanged: (value) { - ref - .read(boardPreferencesProvider.notifier) - .toggleCoordinates(); - }, - ), - SwitchSettingTile( - // TODO translate - leading: const Icon(Icons.border_outer), - title: const Text('Show border'), - value: boardPrefs.showBorder, - onChanged: (value) { - ref.read(boardPreferencesProvider.notifier).toggleBorder(); - }, + ), + onSelectedItemChanged: (ShapeColor? value) { + ref + .read(boardPreferencesProvider.notifier) + .setShapeColor(value ?? ShapeColor.green); + }, + ); + }, + ), + SwitchSettingTile( + leading: const Icon(Icons.location_on), + title: Text( + context.l10n.preferencesBoardCoordinates, ), - ], - ), - ], - ), + value: boardPrefs.coordinates, + onChanged: (value) { + ref.read(boardPreferencesProvider.notifier).toggleCoordinates(); + }, + ), + SwitchSettingTile( + // TODO translate + leading: const Icon(Icons.border_outer), + title: const Text('Show border'), + value: boardPrefs.showBorder, + onChanged: (value) { + ref.read(boardPreferencesProvider.notifier).toggleBorder(); + }, + ), + ], + ), + ], ); } } diff --git a/lib/src/view/study/study_list_screen.dart b/lib/src/view/study/study_list_screen.dart index d76515cf18..f209737c6d 100644 --- a/lib/src/view/study/study_list_screen.dart +++ b/lib/src/view/study/study_list_screen.dart @@ -55,7 +55,7 @@ class StudyListScreen extends ConsumerWidget { ), ], ), - body: SafeArea(child: _Body(filter: filter)), + body: SafeArea(top: false, child: _Body(filter: filter)), ); } } diff --git a/lib/src/view/user/game_history_screen.dart b/lib/src/view/user/game_history_screen.dart index 0d01215b3e..93cd532e69 100644 --- a/lib/src/view/user/game_history_screen.dart +++ b/lib/src/view/user/game_history_screen.dart @@ -157,63 +157,61 @@ class _BodyState extends ConsumerState<_Body> { data: (state) { final list = state.gameList; - return SafeArea( - child: list.isEmpty - ? const Padding( - padding: EdgeInsets.symmetric(vertical: 32.0), - child: Center( - child: Text( - 'No games found', - ), + return list.isEmpty + ? const Padding( + padding: EdgeInsets.symmetric(vertical: 32.0), + child: Center( + child: Text( + 'No games found', ), - ) - : ListView.separated( - controller: _scrollController, - separatorBuilder: (context, index) => - Theme.of(context).platform == TargetPlatform.iOS - ? const PlatformDivider( - height: 1, - cupertinoHasLeading: true, - ) - : const PlatformDivider( - height: 1, - color: Colors.transparent, - ), - itemCount: list.length + (state.isLoading ? 1 : 0), - itemBuilder: (context, index) { - if (state.isLoading && index == list.length) { - return const Padding( - padding: EdgeInsets.symmetric(vertical: 32.0), - child: CenterLoadingIndicator(), - ); - } else if (state.hasError && - state.hasMore && - index == list.length) { - // TODO: add a retry button - return const Padding( - padding: EdgeInsets.symmetric(vertical: 32.0), - child: Center( - child: Text( - 'Could not load more games', + ), + ) + : ListView.separated( + controller: _scrollController, + separatorBuilder: (context, index) => + Theme.of(context).platform == TargetPlatform.iOS + ? const PlatformDivider( + height: 1, + cupertinoHasLeading: true, + ) + : const PlatformDivider( + height: 1, + color: Colors.transparent, ), + itemCount: list.length + (state.isLoading ? 1 : 0), + itemBuilder: (context, index) { + if (state.isLoading && index == list.length) { + return const Padding( + padding: EdgeInsets.symmetric(vertical: 32.0), + child: CenterLoadingIndicator(), + ); + } else if (state.hasError && + state.hasMore && + index == list.length) { + // TODO: add a retry button + return const Padding( + padding: EdgeInsets.symmetric(vertical: 32.0), + child: Center( + child: Text( + 'Could not load more games', ), - ); - } - - return ExtendedGameListTile( - item: list[index], - userId: widget.user?.id, - // see: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/list_tile.dart#L30 for horizontal padding value - padding: Theme.of(context).platform == TargetPlatform.iOS - ? const EdgeInsets.symmetric( - horizontal: 14.0, - vertical: 12.0, - ) - : null, + ), ); - }, - ), - ); + } + + return ExtendedGameListTile( + item: list[index], + userId: widget.user?.id, + // see: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/list_tile.dart#L30 for horizontal padding value + padding: Theme.of(context).platform == TargetPlatform.iOS + ? const EdgeInsets.symmetric( + horizontal: 14.0, + vertical: 12.0, + ) + : null, + ); + }, + ); }, error: (e, s) { debugPrint( diff --git a/lib/src/view/user/perf_stats_screen.dart b/lib/src/view/user/perf_stats_screen.dart index bbb6a612d9..9db550fd7d 100644 --- a/lib/src/view/user/perf_stats_screen.dart +++ b/lib/src/view/user/perf_stats_screen.dart @@ -151,268 +151,266 @@ class _Body extends ConsumerWidget { return perfStats.when( data: (data) { - return SafeArea( - child: ListView( - padding: Styles.bodyPadding, - scrollDirection: Axis.vertical, - children: [ - ratingHistory.when( - data: (ratingHistoryData) { - final ratingHistoryPerfData = ratingHistoryData - .firstWhereOrNull((element) => element.perf == perf); - - if (ratingHistoryPerfData == null || - ratingHistoryPerfData.points.isEmpty) { - return const SizedBox.shrink(); - } - return _EloChart(ratingHistoryPerfData); - }, - error: (error, stackTrace) { - debugPrint( - 'SEVERE: [PerfStatsScreen] could not load rating history data; $error\n$stackTrace', - ); - return const Text('Could not show chart elo chart'); - }, - loading: () { + return ListView( + padding: Styles.bodyPadding.add(MediaQuery.paddingOf(context)), + scrollDirection: Axis.vertical, + children: [ + ratingHistory.when( + data: (ratingHistoryData) { + final ratingHistoryPerfData = ratingHistoryData + .firstWhereOrNull((element) => element.perf == perf); + + if (ratingHistoryPerfData == null || + ratingHistoryPerfData.points.isEmpty) { return const SizedBox.shrink(); - }, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Text( - '${context.l10n.rating} ', - style: Styles.sectionTitle, - ), - RatingWidget( - rating: data.rating, - deviation: data.deviation, - provisional: data.provisional, - style: _mainValueStyle, - ), - ], + } + return _EloChart(ratingHistoryPerfData); + }, + error: (error, stackTrace) { + debugPrint( + 'SEVERE: [PerfStatsScreen] could not load rating history data; $error\n$stackTrace', + ); + return const Text('Could not show chart elo chart'); + }, + loading: () { + return const SizedBox.shrink(); + }, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Text( + '${context.l10n.rating} ', + style: Styles.sectionTitle, + ), + RatingWidget( + rating: data.rating, + deviation: data.deviation, + provisional: data.provisional, + style: _mainValueStyle, + ), + ], + ), + if (perf != Perf.puzzle) ...[ + if (data.percentile != null && data.percentile! > 0.0) + Text( + (loggedInUser != null && loggedInUser.user.id == user.id) + ? context.l10n.youAreBetterThanPercentOfPerfTypePlayers( + '${data.percentile!.toStringAsFixed(2)}%', + perf.title, + ) + : context.l10n.userIsBetterThanPercentOfPerfTypePlayers( + user.username, + '${data.percentile!.toStringAsFixed(2)}%', + perf.title, + ), + style: TextStyle(color: textShade(context, 0.7)), + ), + subStatSpace, + // The number '12' here is not arbitrary, since the API returns the progression for the last 12 games (as far as I know). + StatCard( + context.l10n + .perfStatProgressOverLastXGames('12') + .replaceAll(':', ''), + child: _ProgressionWidget(data.progress), ), - if (perf != Perf.puzzle) ...[ - if (data.percentile != null && data.percentile! > 0.0) - Text( - (loggedInUser != null && loggedInUser.user.id == user.id) - ? context.l10n.youAreBetterThanPercentOfPerfTypePlayers( - '${data.percentile!.toStringAsFixed(2)}%', - perf.title, - ) - : context.l10n.userIsBetterThanPercentOfPerfTypePlayers( - user.username, - '${data.percentile!.toStringAsFixed(2)}%', - perf.title, - ), - style: TextStyle(color: textShade(context, 0.7)), + StatCardRow([ + if (data.rank != null) + StatCard( + context.l10n.rank, + value: data.rank == null + ? '?' + : NumberFormat.decimalPattern( + Intl.getCurrentLocale(), + ).format(data.rank), ), - subStatSpace, - // The number '12' here is not arbitrary, since the API returns the progression for the last 12 games (as far as I know). StatCard( context.l10n - .perfStatProgressOverLastXGames('12') - .replaceAll(':', ''), - child: _ProgressionWidget(data.progress), + .perfStatRatingDeviation('') + .replaceAll(': .', ''), + value: data.deviation.toStringAsFixed(2), ), - StatCardRow([ - if (data.rank != null) - StatCard( - context.l10n.rank, - value: data.rank == null - ? '?' - : NumberFormat.decimalPattern( - Intl.getCurrentLocale(), - ).format(data.rank), - ), - StatCard( - context.l10n - .perfStatRatingDeviation('') - .replaceAll(': .', ''), - value: data.deviation.toStringAsFixed(2), - ), - ]), - StatCardRow([ - StatCard( - context.l10n.perfStatHighestRating('').replaceAll(':', ''), - child: _RatingWidget( - data.highestRating, - data.highestRatingGame, - context.lichessColors.good, - ), + ]), + StatCardRow([ + StatCard( + context.l10n.perfStatHighestRating('').replaceAll(':', ''), + child: _RatingWidget( + data.highestRating, + data.highestRatingGame, + context.lichessColors.good, ), - StatCard( - context.l10n.perfStatLowestRating('').replaceAll(':', ''), - child: _RatingWidget( - data.lowestRating, - data.lowestRatingGame, - context.lichessColors.error, - ), + ), + StatCard( + context.l10n.perfStatLowestRating('').replaceAll(':', ''), + child: _RatingWidget( + data.lowestRating, + data.lowestRatingGame, + context.lichessColors.error, ), - ]), - statGroupSpace, - Semantics( - container: true, - enabled: true, - button: true, - label: context.l10n.perfStatViewTheGames, - child: Tooltip( - excludeFromSemantics: true, - message: context.l10n.perfStatViewTheGames, - child: AdaptiveInkWell( - onTap: () { - pushPlatformRoute( - context, - builder: (context) => GameHistoryScreen( - user: user.lightUser, - isOnline: true, - gameFilter: GameFilterState(perfs: ISet({perf})), + ), + ]), + statGroupSpace, + Semantics( + container: true, + enabled: true, + button: true, + label: context.l10n.perfStatViewTheGames, + child: Tooltip( + excludeFromSemantics: true, + message: context.l10n.perfStatViewTheGames, + child: AdaptiveInkWell( + onTap: () { + pushPlatformRoute( + context, + builder: (context) => GameHistoryScreen( + user: user.lightUser, + isOnline: true, + gameFilter: GameFilterState(perfs: ISet({perf})), + ), + ); + }, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 3.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Text( + '${context.l10n.perfStatTotalGames} ' + .localizeNumbers(), + style: Styles.sectionTitle, ), - ); - }, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 3.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Text( - '${context.l10n.perfStatTotalGames} ' - .localizeNumbers(), - style: Styles.sectionTitle, - ), - Text( - data.totalGames.toString().localizeNumbers(), - style: _mainValueStyle, + Text( + data.totalGames.toString().localizeNumbers(), + style: _mainValueStyle, + ), + Text( + String.fromCharCode( + Icons.arrow_forward_ios.codePoint, ), - Text( - String.fromCharCode( - Icons.arrow_forward_ios.codePoint, - ), - style: Styles.sectionTitle.copyWith( - fontFamily: 'MaterialIcons', - ), + style: Styles.sectionTitle.copyWith( + fontFamily: 'MaterialIcons', ), - ], - ), + ), + ], ), ), ), ), - subStatSpace, - StatCardRow([ - StatCard( - context.l10n.wins, - child: _PercentageValueWidget( - data.wonGames, - data.totalGames, - color: context.lichessColors.good, - ), - ), - StatCard( - context.l10n.draws, - child: _PercentageValueWidget( - data.drawnGames, - data.totalGames, - color: textShade(context, _customOpacity), - isShaded: true, - ), - ), - StatCard( - context.l10n.losses, - child: _PercentageValueWidget( - data.lostGames, - data.totalGames, - color: context.lichessColors.error, - ), - ), - ]), - StatCardRow([ - StatCard( - context.l10n.rated, - child: _PercentageValueWidget( - data.ratedGames, - data.totalGames, - ), - ), - StatCard( - context.l10n.tournament, - child: _PercentageValueWidget( - data.tournamentGames, - data.totalGames, - ), + ), + subStatSpace, + StatCardRow([ + StatCard( + context.l10n.wins, + child: _PercentageValueWidget( + data.wonGames, + data.totalGames, + color: context.lichessColors.good, ), - StatCard( - context.l10n.perfStatBerserkedGames.replaceAll( - ' ${context.l10n.games.toLowerCase()}', - '', - ), - child: _PercentageValueWidget( - data.berserkGames, - data.totalGames, - ), + ), + StatCard( + context.l10n.draws, + child: _PercentageValueWidget( + data.drawnGames, + data.totalGames, + color: textShade(context, _customOpacity), + isShaded: true, ), - StatCard( - context.l10n.perfStatDisconnections, - child: _PercentageValueWidget( - data.disconnections, - data.totalGames, - ), + ), + StatCard( + context.l10n.losses, + child: _PercentageValueWidget( + data.lostGames, + data.totalGames, + color: context.lichessColors.error, ), - ]), - StatCardRow([ - StatCard( - context.l10n.averageOpponent, - value: data.avgOpponent == null - ? '?' - : data.avgOpponent.toString(), + ), + ]), + StatCardRow([ + StatCard( + context.l10n.rated, + child: _PercentageValueWidget( + data.ratedGames, + data.totalGames, ), - StatCard( - context.l10n.perfStatTimeSpentPlaying, - value: data.timePlayed - .toDaysHoursMinutes(AppLocalizations.of(context)), + ), + StatCard( + context.l10n.tournament, + child: _PercentageValueWidget( + data.tournamentGames, + data.totalGames, ), - ]), + ), StatCard( - context.l10n.perfStatWinningStreak, - child: _StreakWidget( - data.maxWinStreak, - data.curWinStreak, - color: context.lichessColors.good, + context.l10n.perfStatBerserkedGames.replaceAll( + ' ${context.l10n.games.toLowerCase()}', + '', + ), + child: _PercentageValueWidget( + data.berserkGames, + data.totalGames, ), ), StatCard( - context.l10n.perfStatLosingStreak, - child: _StreakWidget( - data.maxLossStreak, - data.curLossStreak, - color: context.lichessColors.error, + context.l10n.perfStatDisconnections, + child: _PercentageValueWidget( + data.disconnections, + data.totalGames, ), ), + ]), + StatCardRow([ StatCard( - context.l10n.perfStatGamesInARow, - child: _StreakWidget(data.maxPlayStreak, data.curPlayStreak), + context.l10n.averageOpponent, + value: data.avgOpponent == null + ? '?' + : data.avgOpponent.toString(), ), StatCard( - context.l10n.perfStatMaxTimePlaying, - child: _StreakWidget(data.maxTimeStreak, data.curTimeStreak), + context.l10n.perfStatTimeSpentPlaying, + value: data.timePlayed + .toDaysHoursMinutes(AppLocalizations.of(context)), ), - if (data.bestWins != null && data.bestWins!.isNotEmpty) ...[ - statGroupSpace, - _GameListWidget( - games: data.bestWins!, - perf: perf, - user: user, - header: Text( - context.l10n.perfStatBestRated, - style: Styles.sectionTitle, - ), + ]), + StatCard( + context.l10n.perfStatWinningStreak, + child: _StreakWidget( + data.maxWinStreak, + data.curWinStreak, + color: context.lichessColors.good, + ), + ), + StatCard( + context.l10n.perfStatLosingStreak, + child: _StreakWidget( + data.maxLossStreak, + data.curLossStreak, + color: context.lichessColors.error, + ), + ), + StatCard( + context.l10n.perfStatGamesInARow, + child: _StreakWidget(data.maxPlayStreak, data.curPlayStreak), + ), + StatCard( + context.l10n.perfStatMaxTimePlaying, + child: _StreakWidget(data.maxTimeStreak, data.curTimeStreak), + ), + if (data.bestWins != null && data.bestWins!.isNotEmpty) ...[ + statGroupSpace, + _GameListWidget( + games: data.bestWins!, + perf: perf, + user: user, + header: Text( + context.l10n.perfStatBestRated, + style: Styles.sectionTitle, ), - ], + ), ], ], - ), + ], ); }, error: (error, stackTrace) { diff --git a/lib/src/view/user/player_screen.dart b/lib/src/view/user/player_screen.dart index fd845720f2..a947bacaf4 100644 --- a/lib/src/view/user/player_screen.dart +++ b/lib/src/view/user/player_screen.dart @@ -49,17 +49,15 @@ class _Body extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final session = ref.watch(authSessionProvider); - return SafeArea( - child: ListView( - children: [ - const Padding( - padding: Styles.bodySectionPadding, - child: _SearchButton(), - ), - if (session != null) _OnlineFriendsWidget(), - RatingPrefAware(child: LeaderboardWidget()), - ], - ), + return ListView( + children: [ + const Padding( + padding: Styles.bodySectionPadding, + child: _SearchButton(), + ), + if (session != null) _OnlineFriendsWidget(), + RatingPrefAware(child: LeaderboardWidget()), + ], ); } }