Implement deleting an account
This commit is contained in:
@@ -5,12 +5,11 @@ 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/delete_account.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';
|
||||
import 'package:okane/ui/widgets/piechart.dart';
|
||||
import 'package:okane/ui/widgets/piechart_card.dart';
|
||||
|
||||
class AccountListPage extends StatefulWidget {
|
||||
final bool isPage;
|
||||
@@ -26,6 +25,7 @@ class AccountListPageState extends State<AccountListPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bloc = GetIt.I.get<CoreCubit>();
|
||||
return Stack(
|
||||
children: [
|
||||
ListView(
|
||||
@@ -38,6 +38,79 @@ class AccountListPageState extends State<AccountListPage> {
|
||||
),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: BlocBuilder<CoreCubit, CoreState>(
|
||||
builder:
|
||||
(context, state) => Row(
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed:
|
||||
state.accounts.isEmpty
|
||||
? null
|
||||
: () {
|
||||
showDialogOrModal(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: state.accounts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item =
|
||||
state.accounts[index];
|
||||
return ListTile(
|
||||
title: Text(item.name!),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
color: Colors.red,
|
||||
onPressed: () async {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder:
|
||||
(context) =>
|
||||
DeleteAccountPopup(
|
||||
account: item,
|
||||
onCancel: () {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
},
|
||||
afterDelete: () {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
onTap: () {
|
||||
GetIt.I
|
||||
.get<CoreCubit>()
|
||||
.setActiveAccountIndex(
|
||||
index,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(bloc.activeAccount?.name ?? "None"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: BlocBuilder<CoreCubit, CoreState>(
|
||||
@@ -66,34 +139,26 @@ class AccountListPageState extends State<AccountListPage> {
|
||||
),
|
||||
)
|
||||
: null,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
GetIt.I
|
||||
.get<CoreCubit>()
|
||||
.setActiveAccountIndex(index);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
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!),
|
||||
);
|
||||
},
|
||||
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!),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
66
lib/ui/pages/account/delete_account.dart
Normal file
66
lib/ui/pages/account/delete_account.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
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/ui/state/core.dart';
|
||||
|
||||
class DeleteAccountPopup extends StatelessWidget {
|
||||
final Account account;
|
||||
|
||||
final VoidCallback onCancel;
|
||||
final VoidCallback afterDelete;
|
||||
|
||||
const DeleteAccountPopup({
|
||||
super.key,
|
||||
required this.account,
|
||||
required this.onCancel,
|
||||
required this.afterDelete,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CoreCubit, CoreState>(
|
||||
builder:
|
||||
(context, state) => AlertDialog(
|
||||
title: Text("Delete Account"),
|
||||
content:
|
||||
state.isDeletingAccount
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
"Are you sure you want to delete the account '${account.name!}'? This will delete all transactions as well.",
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed:
|
||||
state.isDeletingAccount
|
||||
? null
|
||||
: () async {
|
||||
await GetIt.I.get<CoreCubit>().deleteAccount(account);
|
||||
afterDelete();
|
||||
},
|
||||
child: Text("Delete", style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed:
|
||||
state.isDeletingAccount
|
||||
? null
|
||||
: () {
|
||||
onCancel();
|
||||
},
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,7 @@ class BeneficiaryListPage extends StatelessWidget {
|
||||
itemBuilder: (context, index) {
|
||||
final item = state.beneficiaries[index];
|
||||
return ListTile(
|
||||
leading: ImageWrapper(
|
||||
title: item.name,
|
||||
path: item.imagePath,
|
||||
),
|
||||
leading: ImageWrapper(title: item.name, path: item.imagePath),
|
||||
title: Text(item.name),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -30,7 +30,10 @@ class SettingsPage extends StatelessWidget {
|
||||
ColorSchemeSettings.values
|
||||
.map(
|
||||
(s) => ListTile(
|
||||
leading: state.settings.colorScheme == s ? Icon(Icons.check) : null,
|
||||
leading:
|
||||
state.settings.colorScheme == s
|
||||
? Icon(Icons.check)
|
||||
: null,
|
||||
title: Text(switch (s) {
|
||||
ColorSchemeSettings.dark => "Dark",
|
||||
ColorSchemeSettings.light => "Light",
|
||||
|
||||
Reference in New Issue
Block a user