Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Flutter with Redux
Search
木藤紘介/Kosuke Kito
December 06, 2018
Programming
3
1.1k
Flutter with Redux
in REQU (
https://requ.ameba.jp/
)
Qiitaはこちら
https://qiita.com/kitoko552/items/155baf852b059550b0f9
木藤紘介/Kosuke Kito
December 06, 2018
Tweet
Share
More Decks by 木藤紘介/Kosuke Kito
See All by 木藤紘介/Kosuke Kito
iOS de Redux
kitoko552
1
84
Other Decks in Programming
See All in Programming
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
1
180
1인 개발자로 행복하게 살기 - GDG 송도 헬로월드 2024
benjaminkim
1
5.6k
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
180
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
3
330
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
250
品質とスピードを両立: TypeScriptの柔軟な型システムをバックエンドで活用する
kosui
8
2.2k
Ruby GitHub Packages
bkuhlmann
0
620
ログラスを支える設計標準について / loglass-design-standards
urmot
10
2.1k
Ruby Function Composition
bkuhlmann
1
330
Git Lint
bkuhlmann
4
740
Ruby Pattern Matching
bkuhlmann
0
920
プールにゆこう
irof
2
120
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Practical Orchestrator
shlominoach
181
9.7k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
GitHub's CSS Performance
jonrohan
1023
450k
What’s in a name? Adding method to the madness
productmarketing
PRO
15
2.6k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
18
1.7k
We Have a Design System, Now What?
morganepeng
42
6.7k
Infographics Made Easy
chrislema
237
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Building Applications with DynamoDB
mza
88
5.6k
Large-scale JavaScript Application Architecture
addyosmani
503
110k
Transcript
Flutter with Redux -REQUͷ߹
౻ߛհ Kosuke Kito @kitoko552 REQU by CyberAgent, Inc. iOS/Swift, Flutter/Dart
Ωϟϯϓข͖ՐεϚϒϥཉ͍͠
https://requ.ameba.jp/
- Unidirectional data flow - Three principles Redux
Unidirectional data flow View Store Reducer State Reducer State Reducer
State Action Middleware Subscribe Dispatch
- Single source of truth - State is read-only -
Changes are made with pure functions Three principles
- ΞϓϦέʔγϣϯશମͷঢ়ଶΛ1ͭͷStoreͰදݱ - ঢ়ଶΛม͔͑ͨͬͨΒ৽͍͠State࡞ͬͯ͘Ε - ঢ়ଶมߋͰ͖ΔͷReducer͚ͩ Three principles
FlutterͰRedux
None
redux:͖ͬ͞ͷͭ flutter_redux: reduxͱWidgetπϦʔͷհ redux_logging: ϩά redux_thunk: ThunkMiddlewareΛఏڙ REQUͷ߹
ThunkMiddleware? View Store Reducer State Reducer State Reducer State Action
Middleware Subscribe Dispatch ThunkMiddleware
ඇಉظॲཧΛActionͱͯ͠ఆٛͰ͖ΔΑ͏ʹ͢ ΔͨΊͷMiddleware ThunkMiddleware?
REQUͷ߹ʢActionʣ class UpdateSomething { UpdateSomething(this.id, this.name); final int id; final
String name; } store.dispatch(UpdateSomething(id, name));
REQUͷ߹ʢActionʣ ThunkAction<AppState> fetchSomething() { return (store) { // ඇಉظॲཧ .then((response)
=> store.dispatch(UpdateSomething(response))) .catchError((error) => store.dispatch(UpdateError(error))); }; } store.dispatch(fetchSomething());
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), ), ), ); }, ); } }
REQUͷ߹ʢViewʣ View Store Reducer State Reducer State Reducer State Action
Middleware Subscribe Dispatch View Model
REQUͷ߹ʢStateʣ @immutable class HomeState { HomeState({@required this.name}); final String name;
HomeState copyWith({String name}) { return HomeState(name: name ?? this.name); } }
REQUͷ߹ʢReducerʣ final Reducer<HomeState> homeReducer = combineReducers<HomeState>([ TypedReducer(_updateName), ]); HomeState _updateName(HomeState
state, UpdateName action) { return state.copyWith(name: action.name); }
- ςετ͕ෆࣗવͳॻ͖ํʹͳΔͱ͜Ζ͕͋Δ - Action͕ଠΓ͕ͪ - AnimatedListͱͷ૬ੑ͕ྑ͘ͳ͍߹͕͋Δ ΜͰ͍Δͱ͜Ζ
- దͳϧʔϧͰറΕΔ =>νʔϜϝϯόʔ୭͕ॻ͍ͯ͋Δఔಉ͡Α͏ͳ࣮ʹͳΔ - FlutterReduxΒͳ͍৽ϝϯόʔʹͱֶͬͯशίετ͕ ߴͯ͘ࠅ - iOSΑΓFlutterͷํ͕૬ੑ͍͍ ײ