Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutter with Redux

Flutter with Redux

木藤紘介/Kosuke Kito

December 06, 2018
Tweet

More Decks by 木藤紘介/Kosuke Kito

Other Decks in Programming

Transcript

  1. - Single source of truth - State is read-only -

    Changes are made with pure functions Three principles
  2. REQUͷ৔߹ʢActionʣ ThunkAction<AppState> fetchSomething() { return (store) { // ඇಉظॲཧ .then((response)

    => store.dispatch(UpdateSomething(response))) .catchError((error) => store.dispatch(UpdateError(error))); }; } store.dispatch(fetchSomething());
  3. REQUͷ৔߹ʢViewʣ class _HomePageState extends State<HomePage> { @override Widget build(BuildContext context)

    { return StoreConnector<AppState, _HomePageViewModel>( distinct: true, converter: (store) { return _HomePageViewModel( name: store.state.homeState.name, onTap: () => store.dispatch(UpdateName('Next name')), ); }, builder: (context, viewModel) { return Scaffold( body: Center( child: FlatButton( onPressed: viewModel.onTap, child: Text(viewModel.name), ), ), ); }, ); } }
  4. REQUͷ৔߹ʢStateʣ @immutable class HomeState { HomeState({@required this.name}); final String name;

    HomeState copyWith({String name}) { return HomeState(name: name ?? this.name); } }