Indicate the active account

This commit is contained in:
PapaTutuWawa 2025-05-04 19:47:11 +02:00
parent eced6e6a6d
commit cf5dcfbc0f
4 changed files with 115 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import 'package:okane/ui/pages/template_list.dart';
import 'package:okane/ui/pages/transaction_details.dart'; import 'package:okane/ui/pages/transaction_details.dart';
import 'package:okane/ui/pages/transaction_list.dart'; import 'package:okane/ui/pages/transaction_list.dart';
import 'package:okane/ui/state/core.dart'; import 'package:okane/ui/state/core.dart';
import 'package:okane/ui/widgets/account_indicator.dart';
enum OkanePage { accounts, transactions, beneficiaries, templates, budgets } enum OkanePage { accounts, transactions, beneficiaries, templates, budgets }
@ -19,6 +20,7 @@ class OkanePageItem {
final String label; final String label;
final Widget child; final Widget child;
final OkanePageBuilder? details; final OkanePageBuilder? details;
final bool showAccountName;
const OkanePageItem( const OkanePageItem(
this.page, this.page,
@ -26,6 +28,7 @@ class OkanePageItem {
this.label, this.label,
this.child, this.child,
this.details, this.details,
this.showAccountName,
); );
NavigationDestination toDestination() => NavigationDestination toDestination() =>
@ -42,6 +45,7 @@ final _pages = <OkanePageItem>[
"Accounts", "Accounts",
AccountListPage(isPage: false), AccountListPage(isPage: false),
null, null,
false,
), ),
OkanePageItem( OkanePageItem(
OkanePage.transactions, OkanePage.transactions,
@ -49,6 +53,7 @@ final _pages = <OkanePageItem>[
"Transactions", "Transactions",
TransactionListPage(), TransactionListPage(),
(_) => TransactionDetailsPage(), (_) => TransactionDetailsPage(),
true,
), ),
OkanePageItem( OkanePageItem(
OkanePage.beneficiaries, OkanePage.beneficiaries,
@ -56,6 +61,7 @@ final _pages = <OkanePageItem>[
"Beneficiaries", "Beneficiaries",
Container(), Container(),
null, null,
true,
), ),
OkanePageItem( OkanePageItem(
OkanePage.templates, OkanePage.templates,
@ -63,6 +69,7 @@ final _pages = <OkanePageItem>[
"Templates", "Templates",
TemplateListPage(), TemplateListPage(),
null, null,
true,
), ),
OkanePageItem( OkanePageItem(
OkanePage.budgets, OkanePage.budgets,
@ -70,6 +77,7 @@ final _pages = <OkanePageItem>[
"Budgets", "Budgets",
BudgetListPage(), BudgetListPage(),
(_) => BudgetDetailsPage(), (_) => BudgetDetailsPage(),
true,
), ),
]; ];
@ -113,9 +121,13 @@ class OkaneNavigationDrawer extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<CoreCubit, CoreState>( return BlocBuilder<CoreCubit, CoreState>(
builder: (context, state) => Drawer( builder:
(context, state) => Drawer(
child: ListView( child: ListView(
children: _pages.map((p) => ListTile( children:
_pages
.map(
(p) => ListTile(
title: Text(p.label), title: Text(p.label),
leading: Icon(p.icon), leading: Icon(p.icon),
selected: p.page == state.activePage, selected: p.page == state.activePage,
@ -123,7 +135,9 @@ class OkaneNavigationDrawer extends StatelessWidget {
context.read<CoreCubit>().setPage(p.page); context.read<CoreCubit>().setPage(p.page);
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
)).toList(), ),
)
.toList(),
), ),
), ),
); );
@ -158,6 +172,20 @@ class OkaneNavigationLayout extends StatelessWidget {
Scaffold.of(context).openDrawer(); Scaffold.of(context).openDrawer();
}, },
), ),
if (p.showAccountName)
Padding(
padding: EdgeInsets.only(left: 8),
child: Text(
state
.accounts[state.activeAccountIndex!]
.name!,
style:
Theme.of(
context,
).textTheme.titleLarge,
),
),
], ],
), ),
), ),
@ -165,7 +193,17 @@ class OkaneNavigationLayout extends StatelessWidget {
Expanded(child: p.child), Expanded(child: p.child),
], ],
), ),
ScreenSize.normal => ScreenSize.normal => Column(
children: [
if (p.showAccountName)
AccountIndicator(
accountName:
state
.accounts[state.activeAccountIndex!]
.name!,
),
Expanded(
child:
p.details != null p.details != null
? Row( ? Row(
children: [ children: [
@ -174,6 +212,9 @@ class OkaneNavigationLayout extends StatelessWidget {
], ],
) )
: p.child, : p.child,
),
],
),
}, },
) )
.toList(), .toList(),

View File

@ -1,6 +1,5 @@
import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:okane/database/collections/budget.dart'; import 'package:okane/database/collections/budget.dart';

View File

@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
class AccountIndicator extends StatelessWidget {
final String accountName;
const AccountIndicator({super.key, required this.accountName});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
accountName,
style: Theme.of(context).textTheme.titleLarge,
),
],
)
);
}
}

30
test/widget_test.dart Normal file
View File

@ -0,0 +1,30 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:okane/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}