概述

#

根據 Flutter 的 棄用策略,已於 3.16 穩定版釋出後生命週期結束的已棄用 API 已被移除。

所有受影響的 API 都已彙總到此主要來源,以幫助遷移。為進一步協助您的遷移,請檢視此 快速參考表

變更

#

本節按軟體包和受影響的類列出了廢棄項。

Button 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