Fix reload bugs when create or delete all wallets; Fix bug when changing chest secret code

This commit is contained in:
poka 2021-11-22 18:45:59 +01:00
parent 7eceac3f66
commit d5aba0e7d1
5 changed files with 50 additions and 12 deletions

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:gecko/models/wallet_data.dart';
import 'package:gecko/screens/home.dart';
class MyWalletsProvider with ChangeNotifier {
List<WalletData> listWallets = [];
@ -71,9 +72,13 @@ class MyWalletsProvider with ChangeNotifier {
await walletBox.clear();
await chestBox.clear();
await configBox.delete('defaultWallet');
rebuildWidget();
// await Future.delayed(const Duration(milliseconds: 50));
// notifyListeners();
Navigator.pop(context);
await Navigator.of(context).pushNamedAndRemoveUntil(
'/',
ModalRoute.withName('/'),
);
}
return 0;
} catch (e) {

View File

@ -49,6 +49,13 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
body: Center(
child: SafeArea(
child: Column(children: <Widget>[
StatefulWrapper(
onInit: () async {
_newWalletFile =
await _changePin.changePin(walletProvider.pinCode);
},
child: Container(),
),
const SizedBox(height: 80),
Text(
'Choisissez un code secret autogénéré :',
@ -112,3 +119,27 @@ class ChangePinScreen extends StatelessWidget with ChangeNotifier {
);
}
}
class StatefulWrapper extends StatefulWidget {
final Function onInit;
final Widget child;
const StatefulWrapper({Key key, @required this.onInit, @required this.child})
: super(key: key);
@override
_StatefulWrapperState createState() => _StatefulWrapperState();
}
class _StatefulWrapperState extends State<StatefulWrapper> {
@override
void initState() {
if (widget.onInit != null) {
widget.onInit();
}
super.initState();
}
@override
Widget build(BuildContext context) {
return widget.child;
}
}

View File

@ -46,7 +46,7 @@ class ChestOptions extends StatelessWidget {
key: const Key('changePin'),
onTap: () async {
// await _chestProvider.changePin(context, cesiumWallet);
walletProvider.pinCode = await Navigator.push(
String pinResult = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
@ -57,6 +57,10 @@ class ChestOptions extends StatelessWidget {
},
),
);
if (pinResult != null) {
walletProvider.pinCode = pinResult;
}
},
child: SizedBox(
height: 50,

View File

@ -137,7 +137,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
onPressed: (_generateWalletProvider
.isAskedWordValid &&
walletName.text != '')
? () {
? () async {
_generateWalletProvider.storeHDWChest(
generatedWallet,
walletName.text,
@ -149,16 +149,16 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier {
_myWalletProvider.listWallets =
_myWalletProvider
.readAllWallets(_currentChest);
scheduleMicrotask(() {
_walletOptions.reloadBuild();
_myWalletProvider.rebuildWidget();
});
await Future.delayed(
const Duration(milliseconds: 50));
_myWalletProvider.rebuildWidget();
Navigator.pushAndRemoveUntil(context,
MaterialPageRoute(builder: (context) {
return UnlockingWallet(
wallet:
_myWalletProvider.getDefaultWallet(
configBox.get('currentChest')),
configBox.get('currentChest'),
),
action: "mywallets",
);
}), ModalRoute.withName('/'));

View File

@ -94,9 +94,7 @@ class SettingsScreen extends StatelessWidget {
),
onPressed: () async => {
log.i('Suppression de tous les wallets'),
await _myWallets
.deleteAllWallet(context)
.then((v) => _homeProvider.rebuildWidget())
await _myWallets.deleteAllWallet(context)
},
child: const Text("EFFACER TOUS MES PORTEFEUILLES",
style: TextStyle(fontSize: 20)))))),