Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Add wallet page (#280)
Browse files Browse the repository at this point in the history
Co-authored-by: I569447 <jonas.sinnhoefer@sap.com>
  • Loading branch information
JJthere and JonasSinnhoefer authored Jun 12, 2024
1 parent 89868c6 commit 2d6751b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
118 changes: 117 additions & 1 deletion client/cashcompass/lib/screens/wallets/wallets_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import 'package:cashcompass/controller/controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../widgets/balance_overview/balance_overview.dart';
import 'package:cashcompass_hook/src/chart_of_accounts.dart/chart_of_accounts.dart';
import 'package:cashcompass_hook/src/data_storage/accout_manager.dart';
import '../../widgets/balance_overview/mock_transaction.dart';
import 'package:cashcompass_hook/src/accounts/category/category.dart';
import 'package:cashcompass_hook/src/accounts/category/category_icons.dart';
import 'package:cashcompass_hook/src/accounts/active_account/active_account.dart';
import 'package:cashcompass_hook/src/accounts/passive_account/passive_account.dart';
import '../../widgets/balance_overview/total_display.dart';

class WalletsScreen extends StatefulWidget {
const WalletsScreen({super.key});
Expand All @@ -8,8 +19,113 @@ class WalletsScreen extends StatefulWidget {
}

class _WalletsScreenState extends State<WalletsScreen> {
late final ChartOfAccounts chart;
late List<ActiveAccount> list;

@override
void initState() {
super.initState();
chart = ChartOfAccounts(Controller.accountManager);

list = chart.getActiveAccounts(); //get all
}

@override
Widget build(BuildContext context) {
return const Center(child: Text('Wallets'));
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text("Wallets"),
),
child: SafeArea(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Text(
'TOTAL: ',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Text(
getTotal().toString(),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: CupertinoColors.systemBlue,
),
),
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: list.length + 1,
itemBuilder: (context, index) {
if (index == 0) {
return CupertinoListTile(
title: Center(
child: CupertinoButton(
onPressed: handleAddCategory,
child: const Text("NEW"),
),
),
);
} else {
ActiveAccount activeAccount = list[index - 1];

return CupertinoListTile(
title: Row(
children: [
Expanded(
flex: 2,
child: Text(activeAccount.name),
),
Expanded(
flex: 3,
child: Text(
"${activeAccount.close()}€",
textAlign: TextAlign.right,
),
),
],
),
onTap: _handleCategoryListTileTapped,
);
}
},
),
],
),
),
),
);
}

InterpretedCategory _interpretCategory(Category category) {
return InterpretedCategory(
categoryIcon: Icons.info,
);
}

void handleAddCategory() {
throw UnsupportedError("Not yet implemented");
}

void _handleCategoryListTileTapped() {
throw UnsupportedError("Not yet implemented");
}

double getTotal() {
double total = 0;
for (ActiveAccount activeAccount in list) {
total += activeAccount.close();
}
return total;
}
}

class InterpretedCategory {
IconData categoryIcon;

InterpretedCategory({this.categoryIcon = Icons.info});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cashcompass_hook/src/accounts/active_account/active_account.dart';
import 'package:cashcompass_hook/src/accounts/category/category.dart';
import 'package:cashcompass_hook/src/data_storage/accout_manager.dart';

Expand All @@ -11,4 +12,12 @@ class ChartOfAccounts {
.where((category) => matcher != null ? matcher(category) : true)
.toList();
}

List<ActiveAccount> getActiveAccounts(
{bool Function(ActiveAccount)? matcher}) {
return _accountmanager
.getAllActiveAccounts()
.where((acc) => matcher != null ? matcher(acc) : true)
.toList();
}
}

0 comments on commit 2d6751b

Please sign in to comment.