Init Project


Use PopScope

WillPopScope deprecated,改使用 PopScope

Untitled

回上一頁,並把資料帶過去

上面已經手動回上一頁了,所以 return false,避免 pop 兩次

Untitled

手動處理 pop,所以 canPop 直接設定成 false

pop 被呼叫時,檢查是否已經成功回到上一頁

實際使用狀況

實際使用狀況


Why Provider

Props Drilling Problem

Untitled

兩個 widget 都要用到同個 state 的話,需要把 state 存在共用的上層

然後再將 state 分別往下傳

但層級比較多的時候,就會出現狀況:

以我們目前的架構為例

Solution: use Provider ( flutter_riverpod )

props flow

props flow

provider flow
要用到 state 的,自己跟 provider 訂閱

provider flow 要用到 state 的,自己跟 provider 訂閱


Install & Init ProviderScope

Getting started | Riverpod

flutter pub add flutter_riverpod

main.dart

main.dart