You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classDatabaseCon {
lateDatabase _database;
DatabaseCon._();
//public factory to call private constructorstaticFuture<DatabaseCon> create() async
{
DatabaseCon dbConn =DatabaseCon._();
dbConn._database =await dbConn._init();
locator.signalReady(dbConn);
return dbConn;
}
Future<Database> get database async {
return _database;
}
Future<Database> _init() async{
var path =join(awaitgetDatabasesPath(), "sampledb.db");
print("path=${path}");
var exists =awaitdatabaseExists(path);
//Not for production. For checkon versions and upgrade, if necessaryawaitdeleteDatabase(path);
exists =awaitdatabaseExists(path);
if (!exists) {
// Make sure the parent directory existstry {
awaitDirectory(dirname(path)).create(recursive:true);
}
catch (_) {
print("exception thrown");
}
ByteData data =await rootBundle.load(join("assets", "sampledb.db"));
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
// Write and flush the bytes writtenawaitFile(path).writeAsBytes(bytes, flush:true);
}
else
{
print("Opening already copied database file");
}
returnawaitopenDatabase(
join(awaitgetDatabasesPath(), "sampledb.db") ,
version:1
);
}
}
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building MyHomePage(dirty, state: _MyHomePageState#ab599):
You tried to access an instance of DatabaseCon that is not ready yet
'package:get_it/get_it_impl.dart':
Failed assertion: line 404 pos 9: 'instanceFactory.isReady'
The relevant error-causing widget was:
MyHomePage MyHomePage:file:///F:/Chapter4/samples/sample/lib/main.dart:32:19
Also please help in understanding the statement locator.registerLazySingleton<AppPreferences>(() => AppPreferences(locator()));
Why locator() is used in AppPreferences(locator())).
Thanks.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Hello all,
I am getting problems will be registering
sqflite
database singleton connection classDatabaseCon
.I register classes like
And the DatabaseCon class
Also please help in understanding the statement
locator.registerLazySingleton<AppPreferences>(() => AppPreferences(locator()));
Why locator() is used in
AppPreferences(locator()))
.Thanks.
The text was updated successfully, but these errors were encountered: