Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Flutterで画面遷移を検知する
Search
kuwapp
April 18, 2018
Programming
8.7k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Flutterで画面遷移を検知する
Flutter meetup Tokyo #1
Flutterで画面遷移を検知する
kuwapp
April 18, 2018
More Decks by kuwapp
See All by kuwapp
FlutterPluginの作り方
kuwapp
7
4.5k
Flutter開発に役立つ Package Plugin 10選
kuwapp
5
17k
Flutter アニメーションはじめの一歩
kuwapp
1
1.5k
Other Decks in Programming
See All in Programming
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
380
JRuby: Past, Present, and Future
headius
0
170
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
560
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
180
一人だけ、Kiroが静止する日
hideg
0
120
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
320
wkhtmltopdfの次どうするか問題2026
willnet
2
1.6k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.9k
Intent as Code
shoppingjaws
6
1.1k
Workers Cache を知る
syumai
0
140
App Intentsのビルドプロセスを支える技術
kntkymt
0
420
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
470
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
290
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
GraphQLとの向き合い方2022年版
quramy
50
15k
How to Ace a Technical Interview
jacobian
281
24k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
How to train your dragon (web standard)
notwaldorf
97
6.8k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
470
The Curse of the Amulet
leimatthew05
3
15k
How GitHub (no longer) Works
holman
316
150k
Faster Mobile Websites
deanohume
310
32k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
The Curious Case for Waylosing
cassininazir
1
520
Transcript
Flutterで画面遷移を検知する Flutter Meetup Tokyo #1
About Me • @kuwapp_dev / Yusuke Hata • モイ株式会社 •
Androidエンジニア • Flutter は alpha のときに二ヶ月程 • メイド喫茶駆動開発
画面遷移を検知できれば... 以下のようなケースに対応できる!!!! 1. 別画面に遷移したら非同期処理停止したい 2. 画面閉じる前に大事なデータ保存しておきたい 3. 画面に戻ったら最新のデータ読み込みたい
Flutter の画面遷移方法 • Navigator.pushNamed(context, “/detail”); ◦ 別画面へ遷移する • Navigator.pop(context); ◦
別画面から戻る(今いる画面を pop する)
どうやって検知しよう??
ベタ書きする?? 画面遷移する処理の上にベタ書きする
(ヾノ・∀・`)ナイナイ
ベタ書きすると • Navigator.push の呼び出し時に必ず書く必要がある • 書き忘れが生じるかもしれない バグのもと!!
画面遷移をいい感じに検知する仕 組みはないのか??
そこで RouteObserver
RouteObserver RouteObserver に登録しておけば、画面遷移時(push pop時)に登録しておいたリス ナーを呼び出してくれる!!
RouteObserver 準備 インスタンスを生 成 navigatorObser versに登録
RouteObserver イベントの購読 • routeObserver.subscribe(this,ModalRoute.of(context)); ◦ push、popのイベントを購読する。 • routeObserver.unsubscribe(this); ◦ イベントの購読をやめる。State
の dispose とかで呼び出そう。 thisにはコールバック先のRouteAwareを指定
RouteObserver 購読 リスナーの RouteAwareを実装 画面遷移のイベントを購読 イベントの購読解除 RouteAware のメソッド push pop
時に呼び出される
RouteObserver RouteAware のメソッド • void didPopNext() ◦ 上に積まれていた画面が pop され自身が表示されたとき
• void didPush() ◦ 自身が push されて表示されたとき • void didPop() ◦ 自身が pop されたとき • void didPushNext() ◦ 次の画面が push されたとき(自身は非表示)
これで画面遷移を検知できるように なった
これでめでたしと思いきや....
RouteObserver は1つの画面 (Route)に1つのリスナーしか登録で きない
RouteObserver の内部実装を見ると Map でリスナーを保持していて 1つの T (Route) に対して 1つの RouteAware(リス
ナー) しか登録できないようになっている final Map<T, RouteAware> _listeners = <T, RouteAware>{}; まじか...
というのは幻想だった
alpha版のときは無理だったが いつの間にかできるようになってい た
Before After Before final Map<T, RouteAware> _listeners = <T, RouteAware>{};
After final Map<R, Set<RouteAware>> _listeners = <R, Set<RouteAware>>{};
Flutterは日々進化する!!!
まとめ • RouteObserver で画面遷移を検知できる • Flutterは日々進化する!最高!
ありがとうございました