I am using dart singleton like this:
class MyHandler {
static final MyHandler _singleton = MyHandler._internal();
Database database;
factory MyHandler({bool initDb}) {
return _singleton;
}
MyHandler._internal() {
initialize();
}
void initialize() async {
// initializing database here
}
}
now my problem is, that when calling initialize on first creation in _internal() a database is instantiated. In my tests I can't access this database so I would like to only execute the initialize()-method when running my app normally but not when doing tests.
That is why I tried to pass a (bool)-parameter on the singleton creation to decide if initialize() should be called or not. Is this possible? I did not find a way to do that. Is there some other solution? Thanks!