myWallets.dart 5.37 KiB
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gecko/globals.dart';
import 'package:provider/provider.dart';
class MyWalletsProvider with ChangeNotifier {
String listWallets;
Future initWalletFolder() async {
await getDefaultWallet();
final bool isWalletFolderExist = await walletsDirectory.exists();
if (!isWalletFolderExist) {
await Directory(walletsDirectory.path).create();
}
File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf');
await _currentChestFile.create();
await _currentChestFile.writeAsString('0');
final bool isChestsExist =
await Directory('${walletsDirectory.path}/0').exists();
if (!isChestsExist) {
await Directory('${walletsDirectory.path}/0').create();
await Directory('${walletsDirectory.path}/1').create();
await File('${walletsDirectory.path}/0/list.conf').create();
await File('${walletsDirectory.path}/0/order.conf').create();
await File('${walletsDirectory.path}/1/list.conf').create();
await File('${walletsDirectory.path}/1/order.conf').create();
}
}
int getCurrentChest() {
File _currentChestFile = File('${walletsDirectory.path}/currentChest.conf');
bool isCurrentChestExist = _currentChestFile.existsSync();
if (!isCurrentChestExist) {
_currentChestFile.createSync();
_currentChestFile.writeAsString('0');
}
return int.parse(_currentChestFile.readAsStringSync());
}
bool checkIfWalletExist() {
if (appPath == null) {
return false;
}
final String _walletList = getAllWalletsNames(0);
if (_walletList == '') {
print('No wallets detected');
return false;
} else {
print('Some wallets have been detected.');
return true;
}
}
String getAllWalletsNames(int _chest) {
if (listWallets != null && listWallets.isNotEmpty) {
listWallets = '';
}
if (listWallets == null) {
listWallets = '';
}