跳至主要內容

v3.7 之後移除的已棄用 API

摘要

#

依照 Flutter 的棄用政策,在 3.7 穩定版發布後達到生命週期結束的已棄用 API 已被移除。

所有受影響的 API 都已編譯到此主要來源中,以協助遷移。同時提供快速參考表

變更

#

本節列出按受影響的類別列出的棄用項目。

GestureRecognizer.kind & 子類別

#

Flutter Fix 支援:是

GestureRecognizer.kind 已在 v2.3 中棄用。請改用 GestureRecognizer.supportedDevices

此相同變更會影響 GestureRecognizer 的所有子類別

  • EagerGestureRecognizer
  • ForcePressGestureRecognizer
  • LongPressGestureRecognizer
  • DragGestureRecognizer
  • VerticalDragGestureRecognizer
  • HorizontalDragGestureRecognizer
  • MultiDragGestureRecognizer
  • ImmediateMultiDragGestureRecognizer
  • HorizontalMultiDragGestureRecognizer
  • VerticalMultiDragGestureRecognizer
  • DelayedMultiDragGestureRecognizer
  • DoubleTapGestureRecognizer
  • MultiTapGestureRecognizer
  • OneSequenceGestureRecognizer
  • PrimaryPointerGestureRecognizer
  • ScaleGestureRecognizer

此變更允許識別手勢的多個裝置,而不是提供的單一選項 kind

遷移指南

遷移前的程式碼

dart
var myRecognizer = GestureRecognizer(
  kind: PointerDeviceKind.mouse,  
);

遷移後的程式碼

dart
var myRecognizer = GestureRecognizer(
  supportedDevices: <PointerDeviceKind>[ PointerDeviceKind.mouse ],
);

參考資料

API 文件

相關 PR


ThemeDataaccentColoraccentColorBrightnessaccentColorTextThemeaccentColorIconThemebuttonColor

#

Flutter Fix 支援:是

ThemeDataaccentColoraccentColorBrightnessaccentColorTextThemeaccentColorIconThemebuttonColor 屬性已在 v2.3 中棄用。

此變更使 ThemeData 更符合 Material Design 指南。它還透過依賴核心配色方案或所需樣式的個別元件主題,在主題設定中建立了更高的清晰度。

框架不再使用 accentColorBrightnessaccentColorTextThemeaccentColorIconThemebuttonColor。應移除參考。

ThemeData.accentColor 的用法應替換為 ThemeData.colorScheme.secondary

遷移指南

#

遷移前的程式碼

dart
var myTheme = ThemeData(
  //...
  accentColor: Colors.blue,
  //...
);
var color = myTheme.accentColor;

遷移後的程式碼

dart
var myTheme = ThemeData(
  //...
  colorScheme: ColorScheme(
    //...
    secondary:Colors.blue,
    //...
  ),
  //...
);
var color = myTheme.colorScheme.secondary;

參考資料

API 文件

相關問題

相關 PR

在以下版本中棄用

在以下版本中移除


AppBarSliverAppBarAppBarTheme 更新

#

Flutter Fix 支援:是

在 v2.4 中,對應用程式列類別及其主題進行了一些變更,以更好地與 Material Design 對齊。當時棄用了一些屬性,並且已被移除。

針對 AppBarSliverAppBarAppBarTheme

  • 已移除 brightness,並由 systemOverlayStyle 取代
  • 已移除 textTheme,並由 toolbarTextStyletitleTextStyle 取代。
  • 可以移除 backwardsCompatibility,因為它是這些屬性的暫時遷移標誌。

此外,還移除了 AppBarTheme.color,並以 AppBarTheme.backgroundColor 取代。

遷移指南

遷移前的程式碼

dart
var toolbarTextStyle = TextStyle(...);
var titleTextStyle = TextStyle(...);
AppBar(
  brightness: Brightness.light,
  textTheme: TextTheme(
    bodyMedium: toolbarTextStyle,
    titleLarge: titleTextStyle,
  )
  backwardsCompatibility: true,
);
AppBarTheme(color: Colors.blue);

遷移後的程式碼

dart
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 仍然支援手動設定覆蓋層,而不是選擇特定模式,讓開發人員可以像以前一樣傳遞相同的覆蓋層清單。

遷移指南

遷移前的程式碼

dart
SystemChrome.setEnabledSystemUIOverlays(<SystemUiOverlay>[
  SystemUiOverlay.top,
  SystemUiOverlay.bottom,
]);

遷移後的程式碼

dart
SystemChrome.setEnabledSystemUIMode(
  SystemUiMode.manual,
  overlays: <SystemUiOverlay>[
    SystemUiOverlay.top,
    SystemUiOverlay.bottom,
  ],
);

參考資料

API 文件

相關問題

在以下版本中棄用

在以下版本中移除


SystemNavigator.routeUpdated

#

Flutter Fix 支援:是

在 v2.3 中,SystemNavigator.routeUpdated 已棄用,並改用 SystemNavigator.routeInformationUpdated

為了避免有兩種方式可以更新引擎關於目前路由,此變更將所有內容移至一個 API,如果建立了報告路由的 Navigator,則該 API 會單獨選取單一項目歷程模式。

遷移指南

遷移前的程式碼

dart
SystemNavigator.routeUpdated(routeName: 'foo', previousRouteName: 'bar');

遷移後的程式碼

dart
SystemNavigator.routeInformationUpdated(location: 'foo');

參考資料

API 文件

相關問題

在以下版本中棄用

在以下版本中移除


AnimatedSize.vsync

#

Flutter Fix 支援:是

在 v2.2 中,AnimatedSize.vsyc 已棄用。在 AnimatedSize 轉換為 StatefulWidget(其 State 混合在 SingleTickerProviderStateMixin 中)之後,此屬性不再必要。進行此變更是為了修正記憶體洩漏。

應移除 vsync 的用法,因為 AnimatedSize 現在會處理此屬性。

遷移指南

遷移前的程式碼

dart
AnimatedSize(
  vsync: this,
  // ...
);

遷移後的程式碼

dart
AnimatedSize(
  // ...
);

參考資料

API 文件

在以下版本中棄用

在以下版本中移除


時間軸

#

在穩定版本中:3.10