Skip to content

Commit

Permalink
chore: ♻️ Refactor main_appbar
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Oct 31, 2024
1 parent f93c953 commit 4211307
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 215 deletions.
2 changes: 2 additions & 0 deletions lib/domain/models/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:freezed_annotation/freezed_annotation.dart';

part 'settings.freezed.dart';

enum MainScreenTab { accountTab, transactionTab, swapTab, earnTab, bridgeTab }

@freezed
class Settings with _$Settings {
const factory Settings({
Expand Down
236 changes: 21 additions & 215 deletions lib/ui/views/main/components/main_appbar.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:ui';

import 'package:aewallet/application/account/providers.dart';
import 'package:aewallet/application/connectivity_status.dart';
import 'package:aewallet/application/session/session.dart';
import 'package:aewallet/application/settings/settings.dart';
import 'package:aewallet/domain/models/settings.dart';
import 'package:aewallet/ui/menu/settings/settings_sheet.dart';
import 'package:aewallet/ui/themes/archethic_theme.dart';
import 'package:aewallet/ui/themes/archethic_theme_base.dart';
import 'package:aewallet/ui/themes/styles.dart';
import 'package:aewallet/ui/util/ui_util.dart';
import 'package:aewallet/ui/views/accounts/layouts/account_list.dart';
import 'package:aewallet/ui/views/accounts/layouts/components/add_account_button.dart';
import 'package:aewallet/ui/views/aeswap_swap/layouts/components/swap_icon_refresh.dart';
import 'package:aewallet/ui/views/main/components/main_appbar_account.dart';
import 'package:aewallet/ui/views/main/components/main_appbar_basic.dart';
import 'package:aewallet/ui/views/main/components/main_appbar_transactions.dart';
import 'package:aewallet/ui/widgets/components/icon_network_warning.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'
as aedappfm;
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';

class MainAppBar extends ConsumerWidget implements PreferredSizeWidget {
const MainAppBar({super.key});
Expand Down Expand Up @@ -63,8 +56,10 @@ class MainAppBar extends ConsumerWidget implements PreferredSizeWidget {
},
),
actions: [
if (preferences.mainScreenCurrentPage == 0 ||
preferences.mainScreenCurrentPage == 1)
if (preferences.mainScreenCurrentPage ==
MainScreenTab.accountTab.index ||
preferences.mainScreenCurrentPage ==
MainScreenTab.transactionTab.index)
IconButton(
icon: Icon(
preferences.showBalances
Expand All @@ -81,216 +76,27 @@ class MainAppBar extends ConsumerWidget implements PreferredSizeWidget {
.setShowBalances(!preferences.showBalances);
},
)
else if (preferences.mainScreenCurrentPage == 2)
else if (preferences.mainScreenCurrentPage ==
MainScreenTab.swapTab.index)
const SwapTokenIconRefresh(),
if (connectivityStatusProvider == ConnectivityStatus.isDisconnected)
const IconNetworkWarning(),
],
title: preferences.mainScreenCurrentPage == 0
? _accountTab(context, ref)
: preferences.mainScreenCurrentPage == 1
? _transactionsTab(context, ref)
: preferences.mainScreenCurrentPage == 2
? FittedBox(
fit: BoxFit.fitWidth,
child: AutoSizeText(
localizations.swapHeader,
style: ArchethicThemeStyles.textStyleSize24W700Primary,
),
)
.animate()
.fade(duration: const Duration(milliseconds: 300))
: preferences.mainScreenCurrentPage == 3
? FittedBox(
fit: BoxFit.fitWidth,
child: AutoSizeText(
localizations.aeSwapEarnHeader,
style:
ArchethicThemeStyles.textStyleSize24W700Primary,
),
)
.animate()
.fade(duration: const Duration(milliseconds: 300))
: FittedBox(
fit: BoxFit.fitWidth,
child: AutoSizeText(
localizations.aeBridgeHeader,
style:
ArchethicThemeStyles.textStyleSize24W700Primary,
),
)
.animate()
.fade(duration: const Duration(milliseconds: 300)),
title: preferences.mainScreenCurrentPage == MainScreenTab.accountTab.index
? const MainAppBarAccount()
: preferences.mainScreenCurrentPage ==
MainScreenTab.transactionTab.index
? const MainAppBarTransactions()
: preferences.mainScreenCurrentPage == MainScreenTab.swapTab.index
? MainAppBarBasic(header: localizations.swapHeader)
: preferences.mainScreenCurrentPage ==
MainScreenTab.earnTab.index
? MainAppBarBasic(header: localizations.aeSwapEarnHeader)
: MainAppBarBasic(header: localizations.aeBridgeHeader),
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
iconTheme: IconThemeData(color: ArchethicTheme.text),
);
}

Widget _accountTab(BuildContext context, WidgetRef ref) {
final localizations = AppLocalizations.of(context)!;
final keychain = ref.watch(
sessionNotifierProvider.select(
(value) => value.loggedIn?.wallet.appKeychain,
),
);
final selectedAccount = ref
.watch(
AccountProviders.accounts,
)
.valueOrNull
?.selectedAccount;
return FittedBox(
fit: BoxFit.fitWidth,
child: InkWell(
onTap: () async {
await showCupertinoModalBottomSheet(
context: context,
builder: (BuildContext context) {
return FractionallySizedBox(
heightFactor: 1,
child: Scaffold(
backgroundColor:
aedappfm.AppThemeBase.sheetBackground.withOpacity(0.2),
body: Stack(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 15),
child: InkWell(
onTap: () {
Clipboard.setData(
ClipboardData(
text:
keychain?.address.toUpperCase() ?? '',
),
);
UIUtil.showSnackbar(
localizations.keychainAddressCopied,
context,
ref,
ArchethicTheme.text,
ArchethicTheme.snackBarShadow,
icon: Symbols.info,
);
},
child: Text(
localizations.accountsHeader,
style: ArchethicThemeStyles
.textStyleSize16W600Primary,
),
),
),
Padding(
padding:
const EdgeInsets.only(top: 10, bottom: 5),
child: RichText(
text: TextSpan(
children: [
const WidgetSpan(
child: Icon(Icons.info, size: 16),
),
TextSpan(
text:
' ${localizations.accountsListWarningRemoveAccount}',
style: ArchethicThemeStyles
.textStyleSize12W100Primary,
),
TextSpan(
text:
' (${localizations.accountsListWarningRemoveAccountConfirmRequired})',
style: ArchethicThemeStyles
.textStyleSize12W100Primary
.copyWith(
fontStyle: FontStyle.italic,
),
),
],
),
),
),
const AccountsList(),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom + 20,
),
child: const Row(
children: [
AddAccountButton(),
],
),
),
),
],
),
),
);
},
);
},
child: Row(
children: [
Text(
selectedAccount?.nameDisplayed ?? ' ',
style: ArchethicThemeStyles.textStyleSize24W700Primary.copyWith(
color: aedappfm.AppThemeBase.secondaryColor,
),
),
const SizedBox(
width: 5,
),
Icon(
Symbols.keyboard_arrow_down,
color: ArchethicThemeBase.neutral0,
),
],
),
),
).animate().fade(duration: const Duration(milliseconds: 300));
}

Widget _transactionsTab(BuildContext context, WidgetRef ref) {
final localizations = AppLocalizations.of(context)!;
final keychain = ref.watch(
sessionNotifierProvider.select(
(value) => value.loggedIn?.wallet.appKeychain,
),
);

return InkWell(
onTap: () {
Clipboard.setData(
ClipboardData(
text: keychain?.address.toUpperCase() ?? '',
),
);
UIUtil.showSnackbar(
localizations.addressCopied,
context,
ref,
ArchethicTheme.text,
ArchethicTheme.snackBarShadow,
icon: Symbols.info,
);
},
child: FittedBox(
fit: BoxFit.fitWidth,
child: AutoSizeText(
localizations.transactionHeader,
style: ArchethicThemeStyles.textStyleSize24W700Primary,
),
).animate().fade(duration: const Duration(milliseconds: 300)),
);
}
}
Loading

0 comments on commit 4211307

Please sign in to comment.