From 3abe991b20afe1dbec59d8f8ab0b33bc84ae9c0e Mon Sep 17 00:00:00 2001 From: Damian Molinski Date: Mon, 14 Oct 2024 14:02:15 +0200 Subject: [PATCH] fix: account page back gesture when there is no previous child in stack --- .../lib/pages/account/account_page.dart | 102 ++++-------------- .../pages/account/account_page_header.dart | 99 +++++++++++++++++ 2 files changed, 118 insertions(+), 83 deletions(-) create mode 100644 catalyst_voices/lib/pages/account/account_page_header.dart diff --git a/catalyst_voices/lib/pages/account/account_page.dart b/catalyst_voices/lib/pages/account/account_page.dart index 6b5d1c4ec20..01144d10d2c 100644 --- a/catalyst_voices/lib/pages/account/account_page.dart +++ b/catalyst_voices/lib/pages/account/account_page.dart @@ -1,4 +1,7 @@ +import 'dart:async'; + import 'package:catalyst_voices/common/ext/account_role_ext.dart'; +import 'package:catalyst_voices/pages/account/account_page_header.dart'; import 'package:catalyst_voices/pages/account/delete_keychain_dialog.dart'; import 'package:catalyst_voices/pages/account/keychain_deleted_dialog.dart'; import 'package:catalyst_voices/widgets/buttons/voices_icon_button.dart'; @@ -12,7 +15,6 @@ import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; import 'package:catalyst_voices_models/catalyst_voices_models.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:go_router/go_router.dart'; final class AccountPage extends StatelessWidget { const AccountPage({super.key}); @@ -23,8 +25,9 @@ final class AccountPage extends StatelessWidget { body: SingleChildScrollView( padding: const EdgeInsets.all(32), child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - const _Header(), + const AccountPageHeader(), Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Column( @@ -41,22 +44,7 @@ final class AccountPage extends StatelessWidget { AccountRole.drep, ], defaultRole: AccountRole.voter, - onRemoveKeychain: () async { - final confirmed = - await DeleteKeychainDialog.show(context); - if (confirmed && context.mounted) { - context - .read() - .add(const RemoveKeychainSessionEvent()); - - await VoicesDialog.show( - context: context, - builder: (context) { - return const KeychainDeletedDialog(); - }, - ); - } - }, + onRemoveKeychain: () => unawaited(_removeKeychain(context)), ), ], ), @@ -66,73 +54,21 @@ final class AccountPage extends StatelessWidget { ), ); } -} -class _Header extends StatelessWidget { - const _Header(); + // Note. probably should redirect somewhere. + Future _removeKeychain(BuildContext context) async { + final confirmed = await DeleteKeychainDialog.show(context); - @override - Widget build(BuildContext context) { - return DecoratedBox( - decoration: BoxDecoration( - image: DecorationImage( - image: CatalystImage.asset( - VoicesAssets.images.accountBg.path, - ).image, - fit: BoxFit.cover, - ), - ), - child: SizedBox( - width: double.infinity, - height: 350, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only( - top: 24, - left: 8, - ), - child: VoicesIconButton.filled( - onTap: () { - GoRouter.of(context).pop(); - }, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colors.elevationsOnSurfaceNeutralLv1White, - ), - foregroundColor: WidgetStateProperty.all( - Theme.of(context).colors.iconsForeground, - ), - ), - child: VoicesAssets.icons.arrowNarrowLeft.buildIcon(), - ), - ), - const Spacer(), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: Text( - context.l10n.myAccountProfileKeychain, - style: Theme.of(context).textTheme.displayMedium?.copyWith( - color: Colors.white, - ), - ), - ), - const SizedBox(height: 4), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 32), - child: Text( - context.l10n.yourCatalystKeychainAndRoleRegistration, - style: Theme.of(context).textTheme.titleMedium?.copyWith( - color: Colors.white, - ), - ), - ), - const SizedBox(height: 48), - ], - ), - ), - ); + if (confirmed && context.mounted) { + context.read().add(const RemoveKeychainSessionEvent()); + + await VoicesDialog.show( + context: context, + builder: (context) { + return const KeychainDeletedDialog(); + }, + ); + } } } diff --git a/catalyst_voices/lib/pages/account/account_page_header.dart b/catalyst_voices/lib/pages/account/account_page_header.dart new file mode 100644 index 00000000000..71d14707d33 --- /dev/null +++ b/catalyst_voices/lib/pages/account/account_page_header.dart @@ -0,0 +1,99 @@ +import 'package:catalyst_voices/routes/routes.dart'; +import 'package:catalyst_voices/widgets/widgets.dart'; +import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; +import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; +import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; + +class AccountPageHeader extends StatelessWidget { + const AccountPageHeader({super.key}); + + @override + Widget build(BuildContext context) { + return Container( + constraints: const BoxConstraints.tightFor(height: 350), + decoration: BoxDecoration( + image: DecorationImage( + image: CatalystImage.asset(VoicesAssets.images.accountBg.path).image, + fit: BoxFit.cover, + ), + ), + child: const Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(height: 24), + Padding( + padding: EdgeInsets.only(left: 8), + child: _BackArrowButton(), + ), + Spacer(), + Padding( + padding: EdgeInsets.symmetric(horizontal: 32), + child: _TitleText(), + ), + SizedBox(height: 4), + Padding( + padding: EdgeInsets.symmetric(horizontal: 32), + child: _SubtitleText(), + ), + SizedBox(height: 48), + ], + ), + ); + } +} + +class _TitleText extends StatelessWidget { + const _TitleText(); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + return Text( + context.l10n.myAccountProfileKeychain, + style: theme.textTheme.displayMedium?.copyWith(color: Colors.white), + ); + } +} + +class _SubtitleText extends StatelessWidget { + const _SubtitleText(); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + return Text( + context.l10n.yourCatalystKeychainAndRoleRegistration, + style: theme.textTheme.titleMedium?.copyWith(color: Colors.white), + ); + } +} + +class _BackArrowButton extends StatelessWidget { + const _BackArrowButton(); + + @override + Widget build(BuildContext context) { + final colors = Theme.of(context).colors; + + final backgroundColor = colors.elevationsOnSurfaceNeutralLv1White; + final foregroundColor = colors.iconsForeground; + return VoicesIconButton.filled( + onTap: () { + if (Navigator.of(context).canPop()) { + Navigator.of(context).pop(); + } else { + GoRouter.of(context).go(Routes.initialLocation); + } + }, + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all(backgroundColor), + foregroundColor: WidgetStateProperty.all(foregroundColor), + ), + child: VoicesAssets.icons.arrowNarrowLeft.buildIcon(), + ); + } +}