Hive migration complete (a few refresh state bugs to fix)

This commit is contained in:
poka 2021-11-07 06:50:09 +01:00
parent 0c55cdc141
commit 6c1fb47799
4 changed files with 20 additions and 14 deletions

View File

@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'dart:async'; import 'dart:async';
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:gecko/models/walletData.dart'; import 'package:gecko/models/walletData.dart';
import 'package:provider/provider.dart';
class MyWalletsProvider with ChangeNotifier { class MyWalletsProvider with ChangeNotifier {
List<WalletData> listWallets = []; List<WalletData> listWallets = [];
@ -34,6 +33,7 @@ class MyWalletsProvider with ChangeNotifier {
} }
List<WalletData> readAllWallets(int _chest) { List<WalletData> readAllWallets(int _chest) {
listWallets.clear();
walletBox.toMap().forEach((key, value) { walletBox.toMap().forEach((key, value) {
if (value.chest == _chest) { if (value.chest == _chest) {
listWallets.add(value); listWallets.add(value);
@ -47,26 +47,30 @@ class MyWalletsProvider with ChangeNotifier {
if (_id.isEmpty) return WalletData(); if (_id.isEmpty) return WalletData();
int _chest = _id[0]; int _chest = _id[0];
int _nbr = _id[1]; int _nbr = _id[1];
var _targetedWallet;
walletBox.toMap().forEach((key, value) { walletBox.toMap().forEach((key, value) {
if (value.chest == _chest && value.number == _nbr) { if (value.chest == _chest && value.number == _nbr) {
return value; _targetedWallet = value;
return false;
} }
}); });
return WalletData(); return _targetedWallet;
} }
void getDefaultWallet() { void getDefaultWallet() {
MyWalletsProvider myWalletsProvider = MyWalletsProvider();
if (configBox.get('defaultWallet') == null) { if (configBox.get('defaultWallet') == null) {
configBox.put('defaultWallet', [0, 0]); configBox.put('defaultWallet', [0, 0]);
} }
defaultWallet = configBox.get('defaultWallet');
defaultWallet = myWalletsProvider
.getWalletData(configBox.get('defaultWallet').cast<int>());
} }
Future<int> deleteAllWallet(context) async { Future<int> deleteAllWallet(context) async {
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
try { try {
log.w('DELETE ALL WALLETS ?'); log.w('DELETE ALL WALLETS ?');
@ -74,9 +78,10 @@ class MyWalletsProvider with ChangeNotifier {
if (_answer) { if (_answer) {
await walletBox.clear(); await walletBox.clear();
await chestBox.clear(); await chestBox.clear();
await configBox.delete('defaultWallet');
checkIfWalletExist();
notifyListeners(); notifyListeners();
rebuildWidget(); rebuildWidget();
_myWalletProvider.rebuildWidget();
Navigator.pop(context); Navigator.pop(context);
} }

View File

@ -34,7 +34,7 @@ class UnlockingWallet extends StatelessWidget {
WalletOptionsProvider _walletOptions = WalletOptionsProvider _walletOptions =
Provider.of<WalletOptionsProvider>(context); Provider.of<WalletOptionsProvider>(context);
log.d("defaultWallet: " + defaultWallet.toString()); // log.d("defaultWallet: " + defaultWallet.toString());
final int _pinLenght = _walletOptions.getPinLenght(wallet.number); final int _pinLenght = _walletOptions.getPinLenght(wallet.number);
errorController = StreamController<ErrorAnimationType>(); errorController = StreamController<ErrorAnimationType>();

View File

@ -50,7 +50,7 @@ class WalletOptions extends StatelessWidget {
_myWalletProvider.getDefaultWallet(); _myWalletProvider.getDefaultWallet();
_walletOptions.isDefaultWallet = _walletOptions.isDefaultWallet =
(defaultWallet.id() == _walletOptions.walletID); (defaultWallet.id()[1] == _walletOptions.walletID[1]);
int currentChest = _myWalletProvider.getCurrentChest(); int currentChest = _myWalletProvider.getCurrentChest();

View File

@ -166,9 +166,10 @@ class WalletsHome extends StatelessWidget {
borderRadius: BorderRadius.vertical( borderRadius: BorderRadius.vertical(
bottom: Radius.circular(12))), bottom: Radius.circular(12))),
// contentPadding: const EdgeInsets.only(left: 7.0), // contentPadding: const EdgeInsets.only(left: 7.0),
tileColor: _repository.id() == defaultWallet.id() tileColor:
? Color(0xffD28928) _repository.id()[1] == defaultWallet.id()[1]
: Color(0xffFFD58D), ? Color(0xffD28928)
: Color(0xffFFD58D),
// leading: Text('IMAGE'), // leading: Text('IMAGE'),
// subtitle: Text(_repository.split(':')[3], // subtitle: Text(_repository.split(':')[3],
@ -181,8 +182,8 @@ class WalletsHome extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 16.0, fontSize: 16.0,
color: _repository.id() == color: _repository.id()[1] ==
defaultWallet.id() defaultWallet.id()[1]
? Color(0xffF9F9F1) ? Color(0xffF9F9F1)
: Colors.black)))), : Colors.black)))),
// dense: true, // dense: true,