flutter_built_redux
flutter_built_redux copied to clipboard
upgrade: Flutter 2
- Upgrade to NNBD
- Replace deprecated method BuildContext.inheritFromWidgetOfExactType
- Replace deprecated
RaisedButton
withElevatedButton
in example
@maxlapides What's the status on this? Is it working for your use case / dependencies? Running into a blocker without this PR or something like it merged. Would be really neat to support it
@bZichett It seems like this flutter_built_redux
project isn't under maintenance anymore, so we migrated away. We're still using built_redux though, so we implemented our own Flutter bindings. I'm happy to share this code with you since it's quite simple. We're using Provider to inject the Redux store dependency, and then we wrote some custom Dart extensions to read/watch values from Redux:
extension ReduxProviderExtension on BuildContext {
T watchRedux<T>(T Function(AppState state) selector) {
return select<ReduxNotifier, T>((notifier) => selector(notifier.state));
}
T readRedux<T>(T Function(AppState state) selector) {
return selector(read<ReduxNotifier>().state);
}
}
class ReduxNotifier extends ChangeNotifier {
ReduxNotifier(this.store) {
_nextStateSubscription = store.nextState.listen((_) => notifyListeners());
}
final AppStore store;
AppState get state => store.state;
late StreamSubscription _nextStateSubscription;
@override
void dispose() {
_nextStateSubscription.cancel();
super.dispose();
}
}
An instance of ReduxNotifier
needs to be provided at the root level of your app:
ChangeNotifierProvider<ReduxNotifier>(
create: (_) => ReduxNotifier(store),
)
And then you can read or watch values from Redux anywhere in your app!
final userId = context.watchRedux((state) => state.userId);
@maxlapides That is most appreciated. I will give it a try tomorrow :+1: