init method
Implementation
Future init(String databaseName) async {
if (initialized) {
return;
}
//Для возможности запуска нескольких экземпляров программы одновременно, пока сделано решение, что для каждого экземпляра будет своя БД
//Решение спорное, но лучше так, чем никак
var iteration = 0;
while (true) {
try {
String localPath = './';
if (!kIsWeb) {
localPath = '${(await getApplicationDocumentsDirectory()).path}/';
}
collection = await BoxCollection.open(
'/$databaseName${iteration++ == 0 ? '' : iteration.toString()}', // Name of database
NsgDataClient.client.getAllRegisteredServerNames().toSet(), // Names of your boxes
path: localPath, // Path where to store your boxes (Only used in Flutter / Dart IO)
//key: null, // Key to encrypt your boxes (Only used in Flutter / Dart IO)
);
} catch (ex) {
if (kDebugMode) {
print(ex);
}
if (iteration < 10) {
continue;
}
}
break;
}
initialized = true;
}