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

List -> detail flow #107

Closed
dawidhyzy opened this issue Feb 18, 2019 · 1 comment
Closed

List -> detail flow #107

dawidhyzy opened this issue Feb 18, 2019 · 1 comment

Comments

@dawidhyzy
Copy link

I'm new to Redux and Flutter. I have a dilemma on how to implement list -> detail flow. Currently, I'm passing selected list element to the detail page and the populating data on view. But I have a feeling that this is violating Redux rules where view should be updated according to app state. My idea is to introduce detail state field to app state and once user select list item dispatch action containing the item and set item in detail state. But I'm not sure if this is the best way to implement that.

I tried to find an answer to my question on GitHub but all of the examples are simple one-page apps.

@brianegan
Copy link
Owner

Currently, I'm passing selected list element to the detail page and the populating data on view.

Hey, sorry -- was on a short vacay. Overall, the way I do it: Pass an id to the detail page. Then, the DetailPage can have a StoreConnector that connects to the Store and use a converter that finds the item in the Store given the Id. Something like this:

class AppState {
  final Map<int, User> users = {
    1: User(name: 'brianegan'),
    2: User(name: 'dawidhyzy'),
  };
}


class UserDetailPage extends StatelessWidget {
  final int userId;

  UserDetailPage({Key key, @required this.userId});

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, User>(
      converter: (store) => store.state.users[userId],
      builder: (context, user) => Text(user.name),
    );
  }
}

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

2 participants