Skip to content
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

[Question] different appbar actions based on state / StoreConnector ? #216

Open
matanshukry opened this issue Jun 4, 2021 · 0 comments
Open

Comments

@matanshukry
Copy link

I have a situation where I want to display different app bar actions based on StoreConnector.
However, I don't want to build the entire Scaffold when the state changes, only the AppBar.

Options I tried / thought of:

  1. Since StoreConnector isn't a PreferredSizeWidget, which is what the appBar argument to Scaffold expect, I can't wrap the entire appbar.
  2. The actions argument expect a list, so I can't wrap that either.
  3. I thought on making a StoreConnector for each possible action, even though that may be null, but we can't return null; so that's not an option.

Example of what I would of wanted

    return Scaffold(
      appBar: StoreConnector<AppState, AuthState>(
        converter: (appState) => appState.state.auth,
        builder: (context, auth) {
          List<Widget> widgets = [];
          if (auth.isLoggedIn) {
            widgets.add(Icon(Icons.star));
          }
          widgets.add(PopupMenuButton<Object>(...));
          return AppBar(title: 'MyApp', actions: actions);
        },
      body: ...
      ),
    );

What should I do about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant