v3.7 後移除的已棄用 API
概述
#根據 Flutter 的棄用政策,在 3.7 穩定版釋出後生命週期已結束的已棄用 API 已被移除。
所有受影響的 API 都已編譯到此主源中,以協助遷移。同時還提供了一份快速參考表。
變更
#本節列出了按受影響類別的棄用內容。
GestureRecognizer.kind & 子類
#Flutter Fix 支援:是
GestureRecognizer.kind 在 v2.3 中被棄用。請改用 GestureRecognizer.supportedDevices。
此更改同樣影響 GestureRecognizer 的所有子類。
EagerGestureRecognizerForcePressGestureRecognizerLongPressGestureRecognizerDragGestureRecognizerVerticalDragGestureRecognizerHorizontalDragGestureRecognizerMultiDragGestureRecognizerImmediateMultiDragGestureRecognizerHorizontalMultiDragGestureRecognizerVerticalMultiDragGestureRecognizerDelayedMultiDragGestureRecognizerDoubleTapGestureRecognizerMultiTapGestureRecognizerOneSequenceGestureRecognizerPrimaryPointerGestureRecognizerScaleGestureRecognizer
此更改允許識別手勢的多個裝置,而不是 kind 提供的單一選項。
遷移指南
遷移前的程式碼
var myRecognizer = GestureRecognizer(
kind: PointerDeviceKind.mouse,
);遷移後的程式碼
var myRecognizer = GestureRecognizer(
supportedDevices: <PointerDeviceKind>[ PointerDeviceKind.mouse ],
);參考資料
API 文件
GestureRecognizerEagerGestureRecognizerForcePressGestureRecognizerLongPressGestureRecognizerDragGestureRecognizerVerticalDragGestureRecognizerHorizontalDragGestureRecognizerMultiDragGestureRecognizerImmediateMultiDragGestureRecognizerHorizontalMultiDragGestureRecognizerVerticalMultiDragGestureRecognizerDelayedMultiDragGestureRecognizerDoubleTapGestureRecognizerMultiTapGestureRecognizerOneSequenceGestureRecognizerPrimaryPointerGestureRecognizerScaleGestureRecognizer
相關 PR
ThemeData 的 accentColor、accentColorBrightness、accentColorTextTheme、accentColorIconTheme 和 buttonColor
#Flutter Fix 支援:是
ThemeData 的 accentColor、accentColorBrightness、accentColorTextTheme、accentColorIconTheme 和 buttonColor 屬性在 v2.3 中被棄用。
此更改使 ThemeData 與 Material Design 指南更好地對齊。它還透過依賴核心配色方案或單獨的元件主題來實現所需的樣式,從而提高了主題設定的清晰度。
框架不再使用 accentColorBrightness、accentColorTextTheme、accentColorIconTheme 和 buttonColor。應移除對此的引用。
ThemeData.accentColor 的用法應替換為 ThemeData.colorScheme.secondary。
遷移指南
#遷移前的程式碼
var myTheme = ThemeData(
//...
accentColor: Colors.blue,
//...
);
var color = myTheme.accentColor;遷移後的程式碼
var myTheme = ThemeData(
//...
colorScheme: ColorScheme(
//...
secondary:Colors.blue,
//...
),
//...
);
var color = myTheme.colorScheme.secondary;參考資料
API 文件
相關問題
相關 PR
棄用自
移除自
AppBar、SliverAppBar 和 AppBarTheme 更新
#Flutter Fix 支援:是
在 v2.4 中,對應用欄類及其主題進行了幾項更改,以更好地與 Material Design 對齊。當時已棄用幾項屬性,現已被移除。
對於 AppBar、SliverAppBar 和 AppBarTheme
brightness已被移除,並由systemOverlayStyle替換。textTheme已被移除,並由toolbarTextStyle或titleTextStyle替換。- 可以移除
backwardsCompatibility,因為它是在這些屬性上的臨時遷移標誌。
此外,AppBarTheme.color 已被移除,並由 AppBarTheme.backgroundColor 替換。
遷移指南
遷移前的程式碼
var toolbarTextStyle = TextStyle(...);
var titleTextStyle = TextStyle(...);
AppBar(
brightness: Brightness.light,
textTheme: TextTheme(
bodyMedium: toolbarTextStyle,
titleLarge: titleTextStyle,
)
backwardsCompatibility: true,
);
AppBarTheme(color: Colors.blue);遷移後的程式碼
var toolbarTextStyle = TextStyle(...);
var titleTextStyle = TextStyle(...);
AppBar(
systemOverlayStyle: SystemOverlayStyle(statusBarBrightness: Brightness.light),
toolbarTextStyle: toolbarTextStyle,
titleTextStyle: titleTextStyle,
);
AppBarTheme(backgroundColor: Colors.blue);參考資料
API 文件
相關問題
棄用自
移除自
SystemChrome.setEnabledSystemUIOverlays
#Flutter Fix 支援:是
在 v2.3 中,用於設定狀態列和導航欄等裝置系統級別覆蓋層的靜態方法 SystemChrome.setEnabledSystemUIOverlays 被棄用,改為使用 SystemChrome.setEnabledSystemUIMode。
此更改允許設定與原生 Android 應用(如沉浸式全屏)匹配的常見全屏模式。
仍然可以透過 SystemUiMode.manual 手動設定覆蓋層,而不是選擇特定模式,這允許開發人員傳遞與以前相同的覆蓋層列表。
遷移指南
遷移前的程式碼
SystemChrome.setEnabledSystemUIOverlays(<SystemUiOverlay>[
SystemUiOverlay.top,
SystemUiOverlay.bottom,
]);遷移後的程式碼
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: <SystemUiOverlay>[
SystemUiOverlay.top,
SystemUiOverlay.bottom,
],
);參考資料
API 文件
相關問題
棄用自
移除自
SystemNavigator.routeUpdated
#Flutter Fix 支援:是
在 v2.3 中,SystemNavigator.routeUpdated 被棄用,改為使用 SystemNavigator.routeInformationUpdated。
該更改將更新引擎當前路由的兩種方式合併為一種 API,如果建立了報告路由的 Navigator,則會單獨選擇單次入口歷史記錄模式。
遷移指南
遷移前的程式碼
SystemNavigator.routeUpdated(routeName: 'foo', previousRouteName: 'bar');遷移後的程式碼
SystemNavigator.routeInformationUpdated(location: 'foo');參考資料
API 文件
相關問題
棄用自
移除自
AnimatedSize.vsync
#Flutter Fix 支援:是
在 v2.2 中,AnimatedSize.vsync 被棄用。在 AnimatedSize 被轉換為 StatefulWidget 且其 State 混入了 SingleTickerProviderStateMixin 後,此屬性不再需要。此更改是為了修復記憶體洩漏。
應移除 vsync 的用法,因為 AnimatedSize 現在已處理此屬性。
遷移指南
遷移前的程式碼
AnimatedSize(
vsync: this,
// ...
);遷移後的程式碼
AnimatedSize(
// ...
);參考資料
API 文件
棄用自
移除自
時間線
#穩定版:3.10