-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StoreConnector for PreferredSizeWidget #23
Comments
Hey there, thanks for writing in :) This is one of the tricky situations! While most of Flutter is Reactive, some parts are imperative: the The simplest thing: Would it be possible to call the If not, in this case, using the
void tabNavigationMiddleware(Store<AppState> store, action, NextDispatcher next) {
// Send the action to your Reducer, it will update the app State
next(action);
// Update the TabController if it's an action we care about
if (action is TabNavigationAction) {
TabScreen.key.currentState.controller.animateTo(store.state.tabIndex);
}
}
class TabNavigationAction {
final TabController controller;
final String someOtherData;
TabNavigationAction(this.controller, this.someOtherData);
}
void tabNavigationMiddleware(Store<AppState> store, action, NextDispatcher next) {
// Send the action to your Reducer, it will update the app State
next(action);
// Update the TabController if it's an action we care about
if (action is TabNavigationAction) {
action.controller.animateTo(store.state.tabIndex);
}
} Great question! Do any of these options work for ya? |
I think you could also do this with a This is actually making me wonder whether I should add an class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
final TabController controller;
MyAppBar({Key key, this.controller}) : super(key: key);
@override
Widget build(BuildContext context) {
return new StoreConnector<AppState, int>(
converter: (store) => store.state.tabIndex,
builder: (context, tabIndex) {
controller.animateTo(tabIndex);
return new AppBar(
bottom: new TabBar(
controller: controller,
tabs: [
new Tab(icon: new Icon(Icons.directions_car)),
new Tab(icon: new Icon(Icons.directions_transit)),
new Tab(icon: new Icon(Icons.directions_bike)),
],
),
title: new Text('Tabs Demo'),
);
}
);
}
@override
Size get preferredSize => new Size.fromHeight(kToolbarHeight);
} |
Thanks for the detailed explanation. I'm pondering the second technique. My specific problem is not knowing what tabs to display until after loading user preferences and fetching some data from a REST API. Initially my The on-boarding case is similar, with the addition that we first need to gather some information from the user and store it in user preferences. And it is also possible for the user to add/remove tabs. I am just learning Flutter and have no prior experience with Redux, but this is the approach I have been taking. I am not sure if an imperative style callback would make more sense or not. |
Yah, that's an interesting problem for sure :) Overall, sounds like what you've got makes total sense. I think it will get tricky with some of those use-cases, such as adding / removing tabs. In those cases, you might have to listen to the Store directly in a |
Also, would love to hear how you solve it in the end! Thanks again for writing :) |
@bdiegel Hey there! With help from the community, I've published a new version of Redux: 0.3.6 for Dart 1 or 0.4.0 for Dart 2. This includes a new |
Heya @bdiegel, is it cool if I close this issue? Happy to help more if you'd like me to keep it open, just trying to keep things tidy! |
Closing for now. Please let me know if you'd like me to re-open :) |
Do you have any suggestions for how to to implement a StoreConnector for a PreferredSizeWidget?
Specifically the example I have is AppBar where bottom is a TabBar. The tabs may need to be updated if the app state changes.
The text was updated successfully, but these errors were encountered: