From 2a096acf7a621040bbbf7e5fcd35f86586c62f63 Mon Sep 17 00:00:00 2001 From: Mikolaj Kieres Date: Thu, 22 Sep 2022 11:24:16 +1000 Subject: [PATCH] small fix of the player's name on the avatar (#121) --- .../lib/common/app_text.dart | 3 ++ .../lib/pages/players/players_page.dart | 4 +- .../lib/pages/settings/settings_page.dart | 37 +++++++++++++++++++ .../player/player_avatar_subtitle_widget.dart | 15 +++----- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/board_games_companion/lib/common/app_text.dart b/board_games_companion/lib/common/app_text.dart index eae37620..4375c449 100644 --- a/board_games_companion/lib/common/app_text.dart +++ b/board_games_companion/lib/common/app_text.dart @@ -131,6 +131,9 @@ class AppText { static const settingsPageBackupButtonText = 'Backup'; static const settingsPageRestireButtonText = 'Restore'; static const settingsPageBackupsListTitle = 'Backups'; + static const settingsPageRestoreSucceededMessage = 'Your data has been successfully restored.'; + static const settingsPageRestoreFailedMessage = + 'Unfortunately we ran into a problem with restoring your data. Please try again or contact support at feedback@progrunning.net'; static const gamePlaytimeFormat = '%s min'; static const gamePlayersSingularFormat = '%i players'; diff --git a/board_games_companion/lib/pages/players/players_page.dart b/board_games_companion/lib/pages/players/players_page.dart index fe6c9656..6c53574d 100644 --- a/board_games_companion/lib/pages/players/players_page.dart +++ b/board_games_companion/lib/pages/players/players_page.dart @@ -131,9 +131,7 @@ class PlayersPageState extends State { actions: [ TextButton( child: const Text(AppText.cancel), - onPressed: () { - Navigator.of(context).pop(false); - }, + onPressed: () => Navigator.of(context).pop(false), ), TextButton( style: TextButton.styleFrom(backgroundColor: AppColors.redColor), diff --git a/board_games_companion/lib/pages/settings/settings_page.dart b/board_games_companion/lib/pages/settings/settings_page.dart index bdc2560e..37efbe27 100644 --- a/board_games_companion/lib/pages/settings/settings_page.dart +++ b/board_games_companion/lib/pages/settings/settings_page.dart @@ -236,11 +236,22 @@ class _BackupSection extends StatefulWidget { class _BackupSectionState extends State<_BackupSection> with TickerProviderStateMixin { late AnimationController _fadeInAnimationController; late AnimationController _sizeAnimationController; + late ReactionDisposer _restoreSuccessReactionDisposer; @override void initState() { super.initState(); + _restoreSuccessReactionDisposer = + reaction((_) => widget.viewModel.visualState, (SettingsPageVisualState visualState) { + final messenger = ScaffoldMessenger.of(context); + visualState.when( + restoringFailure: (errorMessage) => _showRestoreFailureSnackbar(messenger), + initial: () {}, + restoring: () {}, + restoringSuccess: () => _showRestoreSuceededSnackbar(messenger)); + }); + widget.viewModel.loadBackups(); _fadeInAnimationController = AnimationController( @@ -258,6 +269,7 @@ class _BackupSectionState extends State<_BackupSection> with TickerProviderState void dispose() { _fadeInAnimationController.dispose(); _sizeAnimationController.dispose(); + _restoreSuccessReactionDisposer(); super.dispose(); } @@ -364,6 +376,31 @@ class _BackupSectionState extends State<_BackupSection> with TickerProviderState sharePositionOrigin: sharePositionOrigin, ); } + + Future _showRestoreSuceededSnackbar(ScaffoldMessengerState messenger) async { + messenger.showSnackBar( + SnackBar( + behavior: SnackBarBehavior.floating, + margin: Dimensions.snackbarMargin, + content: const Text(AppText.settingsPageRestoreSucceededMessage), + action: SnackBarAction( + label: AppText.ok, + onPressed: () => messenger.hideCurrentSnackBar(reason: SnackBarClosedReason.dismiss), + ), + ), + ); + } + + Future _showRestoreFailureSnackbar(ScaffoldMessengerState messenger) async { + messenger.showSnackBar( + const SnackBar( + behavior: SnackBarBehavior.floating, + margin: Dimensions.snackbarMargin, + content: Text(AppText.settingsPageRestoreFailedMessage), + duration: Duration(seconds: 10), + ), + ); + } } class _BackupFile extends StatelessWidget { diff --git a/board_games_companion/lib/widgets/player/player_avatar_subtitle_widget.dart b/board_games_companion/lib/widgets/player/player_avatar_subtitle_widget.dart index c33aedd8..76fe3597 100644 --- a/board_games_companion/lib/widgets/player/player_avatar_subtitle_widget.dart +++ b/board_games_companion/lib/widgets/player/player_avatar_subtitle_widget.dart @@ -20,23 +20,20 @@ class PlayerAvatarSubtitle extends StatelessWidget { child: Padding( padding: const EdgeInsets.only( bottom: Dimensions.halfStandardSpacing, + left: Dimensions.halfStandardSpacing, + right: Dimensions.halfStandardSpacing, ), child: Container( decoration: BoxDecoration( - borderRadius: const BorderRadius.all( - Radius.circular(AppStyles.defaultCornerRadius), - ), + borderRadius: const BorderRadius.all(Radius.circular(AppStyles.defaultCornerRadius)), color: AppColors.accentColor.withAlpha(AppStyles.opacity70Percent), ), child: Padding( - padding: const EdgeInsets.all( - Dimensions.halfStandardSpacing, - ), + padding: const EdgeInsets.all(Dimensions.halfStandardSpacing), child: Text( player.name ?? '', - style: const TextStyle( - color: AppColors.defaultTextColor, - ), + textAlign: TextAlign.center, + style: const TextStyle(color: AppColors.defaultTextColor), ), ), ),