178 lines
7.0 KiB
Dart
178 lines
7.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:okane/database/collections/account.dart';
|
|
import 'package:okane/database/collections/beneficiary.dart';
|
|
import 'package:okane/database/database.dart';
|
|
import 'package:okane/ui/pages/account/breakdown_card.dart';
|
|
import 'package:okane/ui/pages/account/total_balance_card.dart';
|
|
import 'package:okane/ui/pages/account/upcoming_transactions_card.dart';
|
|
import 'package:okane/ui/state/core.dart';
|
|
import 'package:okane/ui/utils.dart';
|
|
|
|
class AccountListPage extends StatefulWidget {
|
|
final bool isPage;
|
|
|
|
const AccountListPage({required this.isPage, super.key});
|
|
|
|
@override
|
|
AccountListPageState createState() => AccountListPageState();
|
|
}
|
|
|
|
class AccountListPageState extends State<AccountListPage> {
|
|
final TextEditingController _accountNameController = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
ListView(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Text(
|
|
"Accounts",
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
),
|
|
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: BlocBuilder<CoreCubit, CoreState>(
|
|
builder:
|
|
(context, state) => SizedBox(
|
|
child: SizedBox(
|
|
height: 100,
|
|
child: ListView.builder(
|
|
scrollDirection: Axis.horizontal,
|
|
itemCount: state.accounts.length,
|
|
itemBuilder:
|
|
(context, index) => SizedBox(
|
|
width: 150,
|
|
height: 100,
|
|
child: Card(
|
|
color: colorHash(state.accounts[index].name!),
|
|
shape:
|
|
index == state.activeAccountIndex
|
|
? RoundedRectangleBorder(
|
|
side: BorderSide(
|
|
color: Colors.black,
|
|
width: 2,
|
|
),
|
|
borderRadius: BorderRadius.circular(
|
|
12,
|
|
),
|
|
)
|
|
: null,
|
|
child: InkWell(
|
|
onTap: () {
|
|
GetIt.I
|
|
.get<CoreCubit>()
|
|
.setActiveAccountIndex(index);
|
|
},
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(state.accounts[index].name!),
|
|
FutureBuilder(
|
|
future: getTotalBalance(
|
|
state.accounts[index],
|
|
),
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) {
|
|
return Container();
|
|
}
|
|
|
|
return Text(
|
|
formatCurrency(snapshot.data!),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: TotalBalanceCard(),
|
|
),
|
|
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: UpcomingTransactionsCard(),
|
|
),
|
|
|
|
Row(
|
|
children: [
|
|
Padding(padding: EdgeInsets.all(16), child: BreakdownCard()),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
Positioned(
|
|
right: 16,
|
|
bottom: 16,
|
|
child: FloatingActionButton(
|
|
child: Icon(Icons.add),
|
|
onPressed: () {
|
|
showDialogOrModal(
|
|
context: context,
|
|
builder:
|
|
(ctx) => Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
vertical: 8,
|
|
horizontal: 16,
|
|
),
|
|
child: TextField(
|
|
controller: _accountNameController,
|
|
decoration: InputDecoration(
|
|
hintText: "Account name",
|
|
),
|
|
),
|
|
),
|
|
|
|
OutlinedButton(
|
|
onPressed: () async {
|
|
if (_accountNameController.text.isEmpty) return;
|
|
|
|
final a =
|
|
Account()..name = _accountNameController.text;
|
|
final b =
|
|
Beneficiary()
|
|
..name = _accountNameController.text
|
|
..account.value =
|
|
GetIt.I.get<CoreCubit>().activeAccount
|
|
..type = BeneficiaryType.account;
|
|
await upsertAccount(a);
|
|
await upsertBeneficiary(b);
|
|
_accountNameController.text = "";
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text("Add"),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|