cake_wallet/cw_core/lib/pathForWallet.dart

29 lines
938 B
Dart
Raw Normal View History

import 'dart:io';
import 'package:cw_core/root_dir.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:path_provider/path_provider.dart';
2022-10-12 17:09:57 +00:00
Future<String> pathForWalletDir({required String name, required WalletType type}) async {
final root = await getAppDir();
final prefix = walletTypeToString(type).toLowerCase();
final walletsDir = Directory('${root.path}/wallets');
final walletDire = Directory('${walletsDir.path}/$prefix/$name');
if (!walletDire.existsSync()) {
walletDire.createSync(recursive: true);
}
return walletDire.path;
}
2022-10-12 17:09:57 +00:00
Future<String> pathForWallet({required String name, required WalletType type}) async =>
await pathForWalletDir(name: name, type: type)
.then((path) => path + '/$name');
2022-10-12 17:09:57 +00:00
Future<String> outdatedAndroidPathForWalletDir({required String name}) async {
final directory = await getAppDir();
final pathDir = directory.path + '/$name';
return pathDir;
}