跳到主要內容

v3.16 版後已移除的已棄用 API

摘要

#

根據 Flutter 的棄用政策,在 3.16 穩定版本發布後達到生命週期終點的已棄用 API 已被移除。

所有受影響的 API 都已編譯到此主要來源中,以協助遷移。為了進一步協助您遷移,請查看此快速參考表

變更

#

此章節按套件和受影響的類別列出已棄用的項目。

按鈕 styleFrom 屬性

#

套件:flutter,Flutter Fix 支援:是

TextButtonElevatedButtonOutlinedButton 小工具都有一個靜態的 styleFrom 方法,用於產生 ButtonStyle。每個類別的此方法中的以下顏色屬性在 v3.1 中被棄用

  • TextButton.styleFrom
    • primary
    • onSurface
  • ElevatedButton.styleFrom
    • primary
    • onPrimary
    • onSurface
  • OutlinedButton.styleFrom
    • primary
    • onSurface

這些變更使 API 更符合更新的 Material Design 規範。透過將這些屬性替換為 backgroundColorforegroundColordisabledForegroundColor,這些變更也更清楚地說明了顏色如何應用於按鈕。

遷移指南

遷移前的程式碼

dart
TextButton.styleFrom(
  primary: Colors.red,
  onSurface: Colors.black,
);
ElevatedButton.styleFrom(
  primary: Colors.red,
  onPrimary: Colors.blue,
  onSurface: Colors.black,
);
OutlinedButton.styleFrom(
  primary: Colors.red,
  onSurface: Colors.black,
);

遷移後的程式碼

dart
TextButton.styleFrom(
  foregroundColor: Colors.red,
  disabledForegroundColor: Colors.black,
);
ElevatedButton.styleFrom(
  backgroundColor: Colors.red,
  foregroundColor: Colors.blue,
  disabledForegroundColor: Colors.black,
);
OutlinedButton.styleFrom(
  foregroundColor: Colors.red,
  disabledForegroundColor: Colors.black,
);

參考資料

API 文件

相關 PR


ThemeData.selectedRowColor

#

套件:flutter,Flutter Fix 支援:是

ThemeDataselectedRowColor 屬性在 v3.1 中被棄用。

由於使用它的視窗小工具已遷移到其他元件主題,或在更新的 Material Design 規格中不再需要它,因此該屬性不再被框架使用。

遷移指南

遷移前的程式碼

dart
ThemeData(
  // ...
  selectedRowColor: Colors.pink, // Would have no effect.  
);

遷移後的程式碼

dart
ThemeData(
  // ...
  // Remove uses.  
);

參考資料

API 文件

相關 PR


#

套件:flutter,Flutter Fix 支援:是

NavigatorStatefocusScopeNode 屬性在 v3.1 中被棄用。

此變更是為了解決 Navigator 引入的 FocusScopeNode 造成的幾個問題。相反地,FocusScope 被移動到包含 WidgetsApp 中最上層的 NavigatorNavigatorState 被變更為包含自己的 FocusNode,它可從該處參考其 FocusNode.enclosingScope 以存取正確的 FocusScopeNode

遷移指南

遷移前的程式碼

dart
Navigator.of(context).focusScopeNode;

遷移後的程式碼

dart
Navigator.of(context).focusNode.enclosingScope!;

參考資料

API 文件

相關 PR


PlatformMenuBar.body

#

套件:flutter,Flutter Fix 支援:是

PlatformMenuBarbody 屬性在 v3.1 中被棄用。

此變更是為了使 PlatformMenuBar 與框架中的其他視窗小工具保持一致,並將其重新命名為 child

遷移指南

遷移前的程式碼

dart
PlatformMenuBar(
  body: myWidget,
);

遷移後的程式碼

dart
PlatformMenuBar(
  child: myWidget,
);

參考資料

API 文件

相關 PR


先前宣佈的 TextThemeWidgetInspectorServiceWidgetInspectorServiceExtensions 的棄用在本次週期中並未移除。WidgetInspectorServiceWidgetInspectorServiceExtensions 中關於 setPubRootDirectories 的棄用已延長一年,以便 IDE 和其他客戶遷移。預期 TextTheme 的棄用將在下一個週期中移除,屆時將再次宣佈。


時間軸

#

穩定版本:3.19.0