Skip to content

Instantly share code, notes, and snippets.

@xrigau
Created April 16, 2018 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrigau/d0a0ed6f02e259173601b2e31f690df2 to your computer and use it in GitHub Desktop.
Save xrigau/d0a0ed6f02e259173601b2e31f690df2 to your computer and use it in GitHub Desktop.
Introduction to Redux in Flutter (to_do_list_page.dart viewmodel)
class _ViewModel {
final String pageTitle;
final List<_ItemViewModel> items;
final Function onNewItem;
final String newItemToolTip;
_ViewModel(this.pageTitle, this.items, this.onNewItem, this.newItemToolTip, this.newItemIcon);
factory _ViewModel.create(Store<AppState> store) {
List<_ItemViewModel> items = store.state.toDos
.map((ToDoItem item) => /* Omitting some boilerplate here */)
.toList();
return _ViewModel('To Do', items, () => store.dispatch(DisplayListWithNewItemAction()), 'Add new to-do item', Icons.add);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment