I have an sqlite
database from which I read data. I also have a long widget tree. So after a bit of research I found the provider
Flutter package. But I can't figure out how to use Futures inside the class extending ChangeNotifier
or How to use it anywhere in my widget tree?
class MyProvider with ChangeNotifier {
dynamic _myValue;
dynamic get myValue => _myValue;
set myValue(dynamic newValue) {
_myValue = newValue;
notifyListeners();
}
MyProvider(){
loadValue();
}
Future<void> loadValue async {
myValue = await db.instance().getValue();
}
Future<void> refetch async {
myValue = await db.instance().newValue();
notifyListeners();
}
}