I want to get my state from database upon startup. I use provider with ChangeNotivierProvider at my first widget. Code included for clarification.
This is my main method, it has the widget that provides the state i plan to use in the app:
void main() => runApp(
ChangeNotifierProvider(
child: MyApp(),
builder: (context) => StateDao.get(),
),
}
My DAO just returns the state from database (i use sembast, but could just as easily be sqflite or Firebase)
Future<State> get() async {
// Database logic
}
State is just an object extending ChangeNotifier
class State extends ChangeNotifier {
// Getters, setters, changeNotifiers etc.
}
This will not work as i cannot call async methods in the builder-method of ChangeNotifierProvider. How, when and where should this be initialized? As i understand it, async calls should not be done in any build methods. I tried overriding didChangeDependencies that provided context-access but i could not get past the async-call in builder method limitation.