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( 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().deleteAccount(account); afterDelete(); }, child: Text("Delete", style: TextStyle(color: Colors.red)), ), TextButton( onPressed: state.isDeletingAccount ? null : () { onCancel(); }, child: Text("Cancel"), ), ], ), ); } }