prepareDatabaseAndInitialize method
Implementation
Future<bool> prepareDatabaseAndInitialize({
required ByteData license,
required String webServiceUrl,
}) async {
if (_isPreparingDatabase) {
debugPrint("Database preparation already in progress");
return false;
}
_isPreparingDatabase = true;
databasePrepProgress.value = 0.0;
try {
var (success, error) = await DocumentReader.instance.prepareDatabase(
"FullAuth",
(progress) async {
// Update progress state
databasePrepProgress.value = progress.progress.toDouble();
debugPrint("Database preparation progress: ${progress.progress}%");
// Yield to the UI thread periodically to prevent frame drops
// This allows Flutter to process pending frames
await Future.delayed(Duration.zero);
},
);
if (success) {
_isDatabasePrepared = true;
debugPrint("Database prepared successfully");
// Initialize SDK after database preparation is complete
final initSuccess = await initialize(
license: license,
webServiceUrl: webServiceUrl,
);
_isPreparingDatabase = false;
return initSuccess;
} else {
debugPrint("Error preparing database: ${error?.message.toString()}");
_isPreparingDatabase = false;
return false;
}
} catch (e) {
debugPrint("Exception during database preparation: $e");
_isPreparingDatabase = false;
return false;
}
}