Open tbm98 opened 4 years ago
LocatorMixin is not supported by Riverpod.
Yep. just call in constructor and it worked. I think it should be noted in the documentation.
I was looking for LocatorMixin
support but found ProviderReference
instead. You can use ProviderReference
to read your other services.
Providers:
final myLocalServiceProvider = Provider((ref) => MyLocalService());
final myChangeNotifierProvider = ChangeNotifierProvider((ref) => MyChangeNotifier(ref));
ChangeNotifier:
class MyChangeNotifier extends ChangeNotifier {
MyChangeNotifier(this.ref);
final ProviderReference ref;
int count = 43;
void add() {
count++;
notifyListeners();
ref.read(myLocalServiceProvider ).saveLocal(count);
}
void subtract() {
count--;
notifyListeners();
ref.read(myLocalServiceProvider ).saveLocal(count);
}
}
I don't think this is the responsibility of Riverpod to mention this, as LocatorMixin is not exported by Riverpod.
I'll move this to state_notifier instead
Describe the bug StateNotifier not call initState.
To Reproduce
my class:
usage