Fix bugs on startup and deleting wallets

This commit is contained in:
poka 2021-04-04 15:35:38 +02:00 committed by pokapow
parent 94cbb3dfec
commit 263e7d4e88
13 changed files with 65 additions and 12 deletions

View File

@ -44,7 +44,7 @@ Future<void> main() async {
await _homeProvider.getAppPath();
await _homeProvider.createDefaultAvatar();
await _walletsProvider.initWalletFolder();
_walletsProvider.getDefaultWallet();
// _walletsProvider.getDefaultWallet();
appVersion = await _homeProvider.getAppVersion();
prefs = await SharedPreferences.getInstance();
// final HiveStore _store =

View File

@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -21,6 +23,7 @@ class HomeProvider with ChangeNotifier {
Text('Explorateur', style: TextStyle(color: Colors.grey[850]));
List currentTab = [HistoryScreen(), WalletsHome()];
AudioCache player = AudioCache(prefix: 'sounds/');
get currentIndex => _currentIndex;
@ -54,11 +57,15 @@ class HomeProvider with ChangeNotifier {
do {
i++;
log.d(i.toString() + ' ème essai de recherche de endpoint GVA.');
log.d('Try GVA endpoint: ${_listEndpoints[i]}');
if (i > 2) {
log.d('Try GVA endpoint: ${_listEndpoints[i - 1]}');
int listLenght = _listEndpoints.length - 1;
if (i > listLenght) {
log.e('NO VALID GVA ENDPOINT FOUND');
playSound('faché');
_endpoint = 'HS';
break;
} else {
playSound('start');
}
if (i != 0) {
await Future.delayed(const Duration(milliseconds: 300));
@ -121,6 +128,11 @@ class HomeProvider with ChangeNotifier {
notifyListeners();
}
void playSound(String customSound) async {
await player.play('$customSound.wav',
volume: 1, mode: PlayerMode.LOW_LATENCY, stayAwake: false);
}
void handleSearchEnd() {
searchIcon = Icon(
Icons.search,

View File

@ -32,8 +32,9 @@ class MyWalletsProvider with ChangeNotifier {
await File('${walletsDirectory.path}/0/order.conf').create();
await File('${walletsDirectory.path}/1/list.conf').create();
await File('${walletsDirectory.path}/1/order.conf').create();
getDefaultWallet();
// getDefaultWallet();
}
await getDefaultWalletAsync();
}
int getCurrentChest() {
@ -77,6 +78,8 @@ class MyWalletsProvider with ChangeNotifier {
}
WalletData getWalletData(String _id) {
// log.d(_id);
if (_id == '') return WalletData('');
int chest = int.parse(_id.split(':')[0]);
final _walletConfig = File('${walletsDirectory.path}/$chest/list.conf');
@ -85,6 +88,19 @@ class MyWalletsProvider with ChangeNotifier {
.firstWhere((element) => element.startsWith(_id)));
}
Future<WalletData> getWalletDataAsync(String _id) async {
// log.d(_id);
if (_id == '') return WalletData('');
int chest = int.parse(_id.split(':')[0]);
final _walletConfig = File('${walletsDirectory.path}/$chest/list.conf');
List configLines = await _walletConfig.readAsLines();
log.d(configLines);
return WalletData(
configLines.firstWhere((element) => element.startsWith(_id)));
}
void getDefaultWallet() {
defaultWalletFile = File('${appPath.path}/defaultWallet');
@ -96,6 +112,18 @@ class MyWalletsProvider with ChangeNotifier {
defaultWallet = getWalletData(defaultWalletFile.readAsStringSync());
}
Future getDefaultWalletAsync() async {
defaultWalletFile = File('${appPath.path}/defaultWallet');
if (!await defaultWalletFile.exists()) {
await File(defaultWalletFile.path).create();
await defaultWalletFile.writeAsString("0:0");
} else {
defaultWallet =
await getWalletDataAsync(await defaultWalletFile.readAsString());
}
}
Future<int> deleteAllWallet(context) async {
try {
log.w('DELETE THAT ?: $walletsDirectory');
@ -106,9 +134,11 @@ class MyWalletsProvider with ChangeNotifier {
await walletsDirectory.delete(recursive: true);
await defaultWalletFile.delete();
await walletsDirectory.create();
await defaultWalletFile.create();
// await defaultWalletFile.create();
await initWalletFolder();
await Future.delayed(Duration(milliseconds: 100));
notifyListeners();
rebuildWidget();
Navigator.pop(context);
}
return 0;
@ -193,12 +223,14 @@ class WalletData {
// constructor from ':'-separated string
WalletData(String element) {
List parts = element.split(':');
if (element != '') {
List parts = element.split(':');
this.chest = int.parse(parts[0]);
this.number = int.parse(parts[1]);
this.name = parts[2];
this.derivation = int.parse(parts[3]);
this.chest = int.parse(parts[0]);
this.number = int.parse(parts[1]);
this.name = parts[2];
this.derivation = int.parse(parts[3]);
}
}
// representation of WalletData when debugging

View File

@ -28,7 +28,6 @@ class HomeScreen extends StatelessWidget {
isTall = true;
ratio = 1.125;
}
// CommonElements commonElements = CommonElements();
return Scaffold(
resizeToAvoidBottomInset: false,
drawer: Drawer(

View File

@ -119,6 +119,7 @@ class OnboardingStepFourteen extends StatelessWidget {
_myWalletProvider.readAllWallets(_currentChest);
_walletOptions.reloadBuild();
_myWalletProvider.rebuildWidget();
await _myWalletProvider.getDefaultWalletAsync();
Navigator.push(
context,
FaderTransition(

View File

@ -22,6 +22,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
audioplayers:
dependency: "direct main"
description:
name: audioplayers
url: "https://pub.dartlang.org"
source: hosted
version: "0.18.3"
barcode:
dependency: transitive
description:

View File

@ -5,7 +5,7 @@ description: Pay with G1.
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 0.0.1+24
version: 0.0.2+1
environment:
sdk: ">=2.7.0 <3.0.0"
@ -46,6 +46,7 @@ dependencies:
responsive_framework: ^0.0.14
responsive_builder: ^0.3.0
jdenticon_dart: ^2.0.0
audioplayers: ^0.18.3
flutter_icons:
android: "ic_launcher"
@ -69,3 +70,4 @@ flutter:
- assets/onBoarding/
- assets/onBoarding/progress_bar/
- assets/walletOptions/
- sounds/

BIN
sounds/faché.wav Executable file

Binary file not shown.

BIN
sounds/fatigue.wav Executable file

Binary file not shown.

BIN
sounds/gecko.mp3 Normal file

Binary file not shown.

BIN
sounds/non.wav Executable file

Binary file not shown.

BIN
sounds/notif.wav Executable file

Binary file not shown.

BIN
sounds/start.wav Executable file

Binary file not shown.