diff --git a/lib/ui/navigation.dart b/lib/ui/navigation.dart index 16c6b8b..66c218e 100644 --- a/lib/ui/navigation.dart +++ b/lib/ui/navigation.dart @@ -31,11 +31,27 @@ class OkanePageItem { this.showAccountName, ); - NavigationDestination toDestination() => - NavigationDestination(icon: Icon(icon), label: label); + bool _isEnabled(int? accountIndex) { + if (showAccountName) { + return accountIndex != null; + } - NavigationRailDestination toRailDestination() => - NavigationRailDestination(icon: Icon(icon), label: Text(label)); + return true; + } + + NavigationDestination toDestination(int? accountIndex) => + NavigationDestination( + icon: Icon(icon), + label: label, + enabled: _isEnabled(accountIndex), + ); + + NavigationRailDestination toRailDestination(int? accountIndex) => + NavigationRailDestination( + icon: Icon(icon), + label: Text(label), + disabled: !_isEnabled(accountIndex), + ); } final _pages = [ @@ -91,7 +107,10 @@ class OkaneNavigationRail extends StatelessWidget { (context, state) => NavigationRail( onDestinationSelected: (i) => context.read().setPage(_pages[i].page), - destinations: _pages.map((p) => p.toRailDestination()).toList(), + destinations: + _pages + .map((p) => p.toRailDestination(state.activeAccountIndex)) + .toList(), selectedIndex: _pages.indexWhere((p) => p.page == state.activePage), ), ); @@ -108,7 +127,10 @@ class OkaneNavigationBar extends StatelessWidget { (context, state) => NavigationBar( onDestinationSelected: (i) => context.read().setPage(_pages[i].page), - destinations: _pages.map((p) => p.toDestination()).toList(), + destinations: + _pages + .map((p) => p.toDestination(state.activeAccountIndex)) + .toList(), selectedIndex: _pages.indexWhere((p) => p.page == state.activePage), ), ); @@ -173,19 +195,20 @@ class OkaneNavigationLayout extends StatelessWidget { }, ), - if (p.showAccountName) - Padding( - padding: EdgeInsets.only(left: 8), - child: Text( - state - .accounts[state.activeAccountIndex!] - .name!, - style: - Theme.of( - context, - ).textTheme.titleLarge, + 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, + ), ), - ), ], ), ), @@ -195,7 +218,7 @@ class OkaneNavigationLayout extends StatelessWidget { ), ScreenSize.normal => Column( children: [ - if (p.showAccountName) + if (p.showAccountName && state.activeAccountIndex != null) AccountIndicator( accountName: state diff --git a/lib/ui/widgets/add_transaction.dart b/lib/ui/widgets/add_transaction.dart index a32927e..42632c9 100644 --- a/lib/ui/widgets/add_transaction.dart +++ b/lib/ui/widgets/add_transaction.dart @@ -202,7 +202,10 @@ class _AddTransactionWidgetState extends State { ); }) .toList(), - hint: "Beneficiary", + hint: switch (_selectedDirection) { + TransactionDirection.send => "Payee", + TransactionDirection.receive => "Payer", + }, controller: _beneficiaryTextController, selectedValue: _selectedBeneficiary, onSuggestionTap: (beneficiary) { @@ -211,6 +214,30 @@ class _AddTransactionWidgetState extends State { ), ), ), + + Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: SegmentedButton( + segments: [ + ButtonSegment( + value: TransactionDirection.send, + label: Text("Send"), + icon: Icon(Icons.remove), + ), + ButtonSegment( + value: TransactionDirection.receive, + label: Text("Receive"), + icon: Icon(Icons.add), + ), + ], + selected: {_selectedDirection}, + multiSelectionEnabled: false, + onSelectionChanged: (selection) { + setState(() => _selectedDirection = selection.first); + }, + ), + ), + Padding( padding: const EdgeInsets.symmetric(vertical: 8), child: TextField( @@ -274,29 +301,6 @@ class _AddTransactionWidgetState extends State { ], ), - Padding( - padding: const EdgeInsets.symmetric(vertical: 8), - child: SegmentedButton( - segments: [ - ButtonSegment( - value: TransactionDirection.send, - label: Text("Send"), - icon: Icon(Icons.remove), - ), - ButtonSegment( - value: TransactionDirection.receive, - label: Text("Receive"), - icon: Icon(Icons.add), - ), - ], - selected: {_selectedDirection}, - multiSelectionEnabled: false, - onSelectionChanged: (selection) { - setState(() => _selectedDirection = selection.first); - }, - ), - ), - Align( alignment: Alignment.centerRight, child: OutlinedButton(