import 'dart:async'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/substrate_sdk.dart'; import 'package:provider/provider.dart'; class ChestProvider with ChangeNotifier { void rebuildWidget() { notifyListeners(); } Future deleteChest(context, ChestData _chest) async { final bool? _answer = await (_confirmDeletingChest(context, _chest.name)); SubstrateSdk _sub = Provider.of(context, listen: false); if (_answer ?? false) { await _sub.deleteAccounts(getChestWallets(_chest)); await chestBox.delete(_chest.key); MyWalletsProvider _myWalletProvider = Provider.of(context, listen: false); _myWalletProvider.pinCode = ''; if (chestBox.isEmpty) { await configBox.put('currentChest', 0); } else { int? lastChest = chestBox.toMap().keys.first; await configBox.put('currentChest', lastChest); } Navigator.popUntil( context, ModalRoute.withName('/'), ); notifyListeners(); } } List getChestWallets(ChestData _chest) { List toDelete = []; log.d(_chest.key); walletBox.toMap().forEach((key, WalletData value) { if (value.chest == _chest.key) { toDelete.add(value.address!); } }); return toDelete; } Future _confirmDeletingChest(context, String? _walletName) async { return showDialog( context: context, barrierDismissible: true, // user must tap button! builder: (BuildContext context) { return AlertDialog( title: Text('areYouSureToDeleteWallet'.tr(args: [_walletName!])), actions: [ TextButton( child: Text("no".tr(), key: const Key('cancelDeleting')), onPressed: () { Navigator.pop(context, false); }, ), TextButton( child: Text("yes".tr(), key: const Key('confirmDeleting')), onPressed: () { Navigator.pop(context, true); }, ), ], ); }, ); } }