Lock other pages until we have an account

This commit is contained in:
PapaTutuWawa 2025-05-04 20:38:20 +02:00
parent cf5dcfbc0f
commit 6390155f30
2 changed files with 70 additions and 43 deletions

View File

@ -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 = <OkanePageItem>[
@ -91,7 +107,10 @@ class OkaneNavigationRail extends StatelessWidget {
(context, state) => NavigationRail(
onDestinationSelected:
(i) => context.read<CoreCubit>().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<CoreCubit>().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

View File

@ -202,7 +202,10 @@ class _AddTransactionWidgetState extends State<AddTransactionWidget> {
);
})
.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<AddTransactionWidget> {
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SegmentedButton<TransactionDirection>(
segments: [
ButtonSegment(
value: TransactionDirection.send,
label: Text("Send"),
icon: Icon(Icons.remove),
),
ButtonSegment(
value: TransactionDirection.receive,
label: Text("Receive"),
icon: Icon(Icons.add),
),
],
selected: <TransactionDirection>{_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<AddTransactionWidget> {
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SegmentedButton<TransactionDirection>(
segments: [
ButtonSegment(
value: TransactionDirection.send,
label: Text("Send"),
icon: Icon(Icons.remove),
),
ButtonSegment(
value: TransactionDirection.receive,
label: Text("Receive"),
icon: Icon(Icons.add),
),
],
selected: <TransactionDirection>{_selectedDirection},
multiSelectionEnabled: false,
onSelectionChanged: (selection) {
setState(() => _selectedDirection = selection.first);
},
),
),
Align(
alignment: Alignment.centerRight,
child: OutlinedButton(