diff --git a/lib/ui/navigation.dart b/lib/ui/navigation.dart index bc0e7c8..720ee04 100644 --- a/lib/ui/navigation.dart +++ b/lib/ui/navigation.dart @@ -73,7 +73,7 @@ final _pages = [ "Accounts", AccountListPage(isPage: false), null, - false, + true, ), OkanePageItem( OkanePage.transactions, @@ -226,17 +226,10 @@ class OkaneNavigationLayout extends StatelessWidget { if (p.showAccountName && state.activeAccountIndex != null) Padding( - padding: EdgeInsets.only(left: 8), - child: Text( - state - .accounts[state - .activeAccountIndex!] - .name!, - style: - Theme.of( - context, - ).textTheme.titleLarge, + padding: EdgeInsets.symmetric( + horizontal: 8, ), + child: AccountSwitcher(), ), ], ), @@ -249,12 +242,7 @@ class OkaneNavigationLayout extends StatelessWidget { children: [ if (p.showAccountName && state.activeAccountIndex != null) - AccountIndicator( - accountName: - state - .accounts[state.activeAccountIndex!] - .name!, - ), + AccountIndicator(), Expanded( child: p.details != null diff --git a/lib/ui/pages/account/account.dart b/lib/ui/pages/account/account.dart index 09701dd..25f3ebd 100644 --- a/lib/ui/pages/account/account.dart +++ b/lib/ui/pages/account/account.dart @@ -32,90 +32,6 @@ class AccountListPageState extends State { children: [ ListView( children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), - child: Text( - t.pages.accounts.title, - style: Theme.of(context).textTheme.titleLarge, - ), - ), - - Padding( - padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), - child: BlocBuilder( - builder: - (context, state) => Row( - children: [ - OutlinedButton( - onPressed: - state.accounts.isEmpty - ? null - : () { - showDialogOrModal( - context: context, - builder: - (context) => ListView.builder( - shrinkWrap: true, - itemCount: state.accounts.length, - itemBuilder: (context, index) { - final item = - state.accounts[index]; - return ListTile( - title: Text(item.name!), - trailing: IconButton( - icon: Icon(Icons.delete), - color: Colors.red, - onPressed: () async { - await showDialog( - context: context, - barrierDismissible: false, - builder: - (context) => - DeleteAccountPopup( - account: item, - onCancel: () { - Navigator.of( - context, - ).pop(); - Navigator.of( - context, - ).pop(); - }, - afterDelete: () { - Navigator.of( - context, - ).pop(); - Navigator.of( - context, - ).pop(); - }, - ), - ); - }, - ), - onTap: () { - GetIt.I - .get() - .setActiveAccountIndex( - index, - ); - Navigator.of(context).pop(); - }, - ); - }, - ), - ); - }, - child: Text( - bloc.activeAccount?.name ?? - t.pages.accounts.accountSelector.none, - ), - ), - ], - ), - ), - ), - Padding( padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: BlocBuilder( diff --git a/lib/ui/widgets/account_indicator.dart b/lib/ui/widgets/account_indicator.dart index a8bb875..e60af9f 100644 --- a/lib/ui/widgets/account_indicator.dart +++ b/lib/ui/widgets/account_indicator.dart @@ -1,11 +1,86 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:get_it/get_it.dart'; +import 'package:okane/ui/pages/account/delete_account.dart'; +import 'package:okane/ui/state/core.dart'; +import 'package:okane/ui/utils.dart'; + +class AccountSwitcher extends StatelessWidget { + const AccountSwitcher({super.key}); + + @override + Widget build(BuildContext context) { + final bloc = GetIt.I.get(); + return BlocBuilder( + builder: + (context, state) => InkWell( + borderRadius: BorderRadius.circular(8), + onTap: () { + showDialogOrModal( + context: context, + builder: + (context) => ListView.builder( + shrinkWrap: true, + itemCount: state.accounts.length, + itemBuilder: (context, index) { + final item = state.accounts[index]; + return ListTile( + title: Text(item.name!), + trailing: IconButton( + icon: Icon(Icons.delete), + color: Colors.red, + onPressed: () async { + await showDialog( + context: context, + barrierDismissible: false, + builder: + (context) => DeleteAccountPopup( + account: item, + onCancel: () { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + }, + afterDelete: () { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + }, + ), + ); + }, + ), + onTap: () { + GetIt.I.get().setActiveAccountIndex( + index, + ); + Navigator.of(context).pop(); + }, + ); + }, + ), + ); + }, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + bloc.activeAccount!.name!, + style: Theme.of(context).textTheme.titleLarge, + ), + Icon(Icons.arrow_drop_down), + ], + ), + ), + ), + ); + } +} class AccountIndicator extends StatelessWidget { - final String accountName; - final Widget? trailing; - const AccountIndicator({super.key, this.trailing, required this.accountName}); + const AccountIndicator({super.key, this.trailing}); @override Widget build(BuildContext context) { @@ -15,11 +90,8 @@ class AccountIndicator extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, children: [ Padding( - padding: EdgeInsets.all(8), - child: Text( - accountName, - style: Theme.of(context).textTheme.titleLarge, - ), + padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: AccountSwitcher(), ), const Spacer(), if (trailing != null) trailing!,