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.2k
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
85
Other Decks in Programming
See All in Programming
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
Ethereum_.pdf
nekomatu
0
460
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Jakarta EE meets AI
ivargrimstad
0
580
Click-free releases & the making of a CLI app
oheyadam
2
120
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Optimizing for Happiness
mojombo
376
70k
What's new in Ruby 2.0
geeforr
343
31k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Faster Mobile Websites
deanohume
305
30k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Typedesign – Prime Four
hannesfritz
40
2.4k
4 Signs Your Business is Dying
shpigford
180
21k
We Have a Design System, Now What?
morganepeng
50
7.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
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ͷํ͕૬ੑ͍͍ ײ