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
86
Other Decks in Programming
See All in Programming
SwiftUI移行のためのインプレッショントラッキング基盤の構築
kokihirokawa
0
170
[JAWS DAYS 2025] 最近の DB の競合解決の仕組みが分かった気になってみた
maroon1st
0
170
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
210
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
9
1.5k
Swift Testingのモチベを上げたい
stoticdev
2
200
バッチを作らなきゃとなったときに考えること
irof
2
550
JAWS Days 2025のインフラ
komakichi
1
330
ソフトウェアエンジニアの成長
masuda220
PRO
12
2.2k
Better Code Design in PHP
afilina
0
180
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
430
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
410
仕様変更に耐えるための"今の"DRY原則を考える
mkmk884
9
3.3k
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Practical Orchestrator
shlominoach
186
10k
A Philosophy of Restraint
colly
203
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
GraphQLの誤解/rethinking-graphql
sonatard
69
10k
Designing for Performance
lara
605
68k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
A Modern Web Designer's Workflow
chriscoyier
693
190k
GraphQLとの向き合い方2022年版
quramy
44
14k
Git: the NoSQL Database
bkeepers
PRO
428
65k
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ͷํ͕૬ੑ͍͍ ײ