v1.22 後移除的已棄用 API
概述
#根據 Flutter 的棄用策略,在 1.22 穩定版釋出後生命週期結束的已棄用 API 已被移除。這是 Flutter 首次移除已棄用 API,其中一些棄用甚至早於我們的遷移指南策略。
所有受影響的 API 都已整理到這個主要原始檔中,以協助遷移。您還可以找到一個快速參考表。
關於 Flutter 棄用策略的更多背景資訊,請參閱設計文件和文章。
變更
#本節列出了按受影響類別的棄用內容。
CupertinoDialog
#由修復工具支援:僅 IDE 修復。
CupertinoDialog 在 v0.2.3 中已被棄用。請改用 CupertinoAlertDialog 或 CupertinoPopupSurface。
遷移指南
CupertinoAlertDialog
遷移前的程式碼
CupertinoDialog(child: myWidget);遷移後的程式碼
CupertinoAlertDialog(content: myWidget);CupertinoPopupSurface
遷移前的程式碼
CupertinoDialog(child: myWidget);遷移後的程式碼
CupertinoPopupSurface(child: myWidget);參考資料
API 文件
相關問題
相關 PR
Cupertino 導航欄的 actionsForegroundColor
#由修復工具支援:否
CupertinoNavigationBar.actionsForegroundColor 和 CupertinoSliverNavigationBar.actionsForegroundColor 在 v1.1.2 中已被棄用。現在可以透過設定 CupertinoTheme 中的 primaryColor 來實現此功能。要訪問 primaryColor,請呼叫 CupertinoTheme.of(context).primaryColor。
遷移指南
遷移前的程式碼
CupertinoNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);
CupertinoSliverNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);遷移後的程式碼
CupertinoTheme(
data: CupertinoThemeData(
primaryColor: CupertinoColors.systemBlue
),
child: ...
);
// To access the color from the `CupertinoTheme`
CupertinoTheme.of(context).primaryColor;參考資料
API 文件
相關問題
相關 PR
CupertinoTextThemeData.brightness
#由修復工具支援:是
CupertinoTextThemeData.brightness 在 v1.10.14 中已被棄用。此欄位在棄用時已失效。該引數沒有替代方案,應移除相關引用。
遷移指南
遷移前的程式碼
const CupertinoTextThemeData themeData = CupertinoTextThemeData(brightness: Brightness.dark);
themeData.copyWith(brightness: Brightness.light);遷移後的程式碼
const CupertinoTextThemeData themeData = CupertinoTextThemeData();
themeData.copyWith();參考資料
API 文件
相關問題
相關 PR
由 fromHoverEvent 構建的 Pointer 事件
#由修復工具支援:是
PointerEnterEvent 和 PointerExitEvent 的 fromHoverEvent 建構函式在 v1.4.3 中已被棄用。應改用 fromMouseEvent 建構函式。
遷移指南
遷移前的程式碼
final PointerEnterEvent enterEvent = PointerEnterEvent.fromHoverEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromHoverEvent(PointerHoverEvent());遷移後的程式碼
final PointerEnterEvent enterEvent = PointerEnterEvent.fromMouseEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromMouseEvent(PointerHoverEvent());參考資料
API 文件
相關問題
相關 PR
showDialog 使用 builder
#由修復工具支援:是
showDialog 的 child 引數在 v0.2.3 中已被棄用。應改用 builder 引數。
遷移指南
遷移前的程式碼
showDialog(child: myWidget);遷移後的程式碼
showDialog(builder: (context) => myWidget);參考資料
API 文件
相關問題
相關 PR
Scaffold.resizeToAvoidBottomPadding
#由修復工具支援:是
Scaffold 的 resizeToAvoidBottomPadding 引數在 v1.1.9 中已被棄用。應改用 resizeToAvoidBottomInset 引數。
遷移指南
遷移前的程式碼
Scaffold(resizeToAvoidBottomPadding: true);遷移後的程式碼
Scaffold(resizeToAvoidBottomInset: true);參考資料
API 文件
相關問題
- 巢狀 Scaffold 時顯示警告
- 鍵盤附帶的 SafeArea
- 雙重堆疊的 material Scaffold 不應 double resizeToAvoidBottomPadding
- Window 和 MediaQueryData 的 viewInsets 和 padding 應定義它們如何互動
- 當在 tabbarview 中使用 textfields 時,底部溢位問題
相關 PR
ButtonTheme.bar
#由修復工具支援:否
ButtonTheme 的 bar 建構函式在 v1.9.1 中已被棄用。對於 ButtonBar,可以使用 ButtonBarTheme;如果使用場景不限於 ButtonBar,則可以使用 ButtonTheme 的其他建構函式。
按鈕特定的主題也可以透過 TextButtonTheme、ElevatedButtonTheme 和 OutlinedButtonTheme 類獲得,每個類分別對應相應的按鈕類 TextButton、ElevatedButton 和 OutlinedButton。
遷移指南
遷移前的程式碼
ButtonTheme.bar(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);遷移後使用 ButtonTheme 的程式碼
ButtonTheme(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);遷移後使用 ButtonBarTheme 的程式碼
ButtonBarTheme(
data: ButtonBarThemeData(
buttonMinWidth: 10.0,
buttonAlignedDropdown: true,
buttonHeight: 40.0,
)
);參考資料
API 文件
ButtonThemeButtonBarThemeButtonBarTextButtonTheme文字按鈕ElevatedButtonTheme凸起按鈕OutlinedButtonThemeOutlinedButton
相關問題
- ButtonTheme.bar 在應使用 primary color 時使用了 accent color
- ThemeData.accentColor 對文字的對比度不足
- 由於 materialTapTargetSize 的更改,AlertDialog/ButtonBar 的高度增加
相關 PR
InlineSpan, TextSpan, PlaceholderSpan
#由修復工具支援:否
為了能夠將 widget 內聯嵌入段落中(例如影像),InlineSpan、TextSpan 和 PlaceholderSpan 中的以下方法已被棄用。
遷移指南
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
InlineSpan.text | TextSpan.text |
InlineSpan.children | TextSpan.children |
InlineSpan.visitTextSpan | InlineSpan.visitChildren |
InlineSpan.recognizer | TextSpan.recognizer |
InlineSpan.describeSemantics | InlineSpan.computeSemanticsInformation |
PlaceholderSpan.visitTextSpan | PlaceHolderSpan.visitChildren |
TextSpan.visitTextSpan | TextSpan.visitChildren |
參考資料
API 文件
相關問題
相關 PR
RenderView.scheduleInitialFrame
#由修復工具支援:否
RenderView.scheduleInitialFrame 方法已被棄用並移除,以防止啟動畫面過早關閉,導致出現黑屏。當呼叫 WidgetsFlutterBinding.ensureInitialized 時會出現這種情況。請改用 RenderView.prepareInitialFrame,然後是 RenderView.owner.requestVisualUpdate 來替換對該方法的呼叫。
遷移指南
遷移前的程式碼
scheduleInitialFrame();遷移後的程式碼
prepareInitialFrame();
owner.requestVisualUpdate();參考資料
API 文件
相關問題
相關 PR
Layer.findAll
#由修復工具支援:否
Layer.findAll 方法隨著 Layer.findAnnotations 的引入而被棄用,目的是統一 find 和 findAll 的實現。要遷移受影響的程式碼,請改用 findAllAnnotations。此方法返回一個 AnnotationResult,其中包含 findAll 的前返回值,位於 AnnotationResult.annotations 中。
遷移指南
遷移前的程式碼
findAll(offset);遷移後的程式碼
findAllAnnotations(offset).annotations;參考資料
API 文件
相關問題
相關 PR
BinaryMessages
#由修復工具支援:否
BinaryMessages 類、其相關的靜態方法和 defaultBinaryMessenger getter 已被棄用並移除。defaultBinaryMessenger 例項已移至 ServicesBinding。這使得在測試環境中註冊不同的預設 BinaryMessenger 成為可能,方法是建立一個用於測試的 ServicesBinding 子類。這樣做可以讓你跟蹤待處理的平臺訊息數量以進行同步。
遷移指南
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
defaultBinaryMessenger | ServicesBinding.instance.defaultBinaryMessenger |
BinaryMessages | BinaryMessenger |
BinaryMessages.handlePlatformMessage | ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage |
BinaryMessages.send | ServicesBinding.instance.defaultBinaryMessenger.send |
BinaryMessages.setMessageHandler | ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler |
BinaryMessages.setMockMessageHandler | ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler |
參考資料
API 文件
相關問題
相關 PR
BuildContext 的通用方法
#由修復工具支援:是
BuildContext 中的幾個方法曾使用 Type 來搜尋祖先。其中大多數方法在呼叫處暗示了一個型別轉換,因為它們的返回型別是一個父型別。此外,即使型別實際上受約束,在分析時也不會檢查提供的型別。將這些方法改為泛型可以提高型別安全性並減少程式碼量。
這些方法更改影響了 BuildContext、Element 和 StatefulElement 類。TypeMatcher 類也被移除了。
遷移指南
遷移前的程式碼
ComplexLayoutState state = context.ancestorStateOfType(const TypeMatcher<ComplexLayoutState>()) as ComplexLayoutState;遷移後的程式碼
ComplexLayoutState state = context.ancestorStateOfType<ComplexLayoutState>();BuildContext
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
inheritFromElement | dependOnInheritedElement |
inheritFromWidgetOfExactType | dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType | getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType | findAncestorWidgetOfExactType |
ancestorStateOfType | findAncestorStateOfType |
rootAncestorStateOfType | findRootAncestorStateOfType |
ancestorRenderObjectOfType | findAncestorRenderObjectOfType |
Element
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
inheritFromElement | dependOnInheritedElement |
inheritFromWidgetOfExactType | dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType | getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType | findAncestorWidgetOfExactType |
ancestorStateOfType | findAncestorStateOfType |
rootAncestorStateOfType | findRootAncestorStateOfType |
ancestorRenderObjectOfType | findAncestorRenderObjectOfType |
StatefulElement
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
inheritFromElement | dependOnInheritedElement |
參考資料
API 文件
相關 PR
WidgetsBinding.deferFirstFrameReport 和 WidgetsBinding.allowFirstFrameReport
#由修復工具支援:是
WidgetsBinding 的 deferFirstFrameReport 和 allowFirstFrameReport 方法已被棄用並移除,目的是提供延遲渲染第一幀的選項。這對於需要非同步獲取初始化資訊的 widget 很有用,並且在等待該資訊時,不應渲染任何幀,因為這會過早關閉啟動畫面。應分別使用 deferFirstFrame 和 allowFirstFrame 方法來代替。
遷移指南
遷移前的程式碼
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrameReport();
binding.allowFirstFrameReport();遷移後的程式碼
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrame();
binding.allowFirstFrame();參考資料
API 文件
相關 PR
WaitUntilNoTransientCallbacks、WaitUntilNoPendingFrame 和 WaitUntilFirstFrameRasterized
#由修復工具支援:否
flutter_driver 包中的 WaitUntilNoTransientCallbacks、WaitUntilNoPendingFrame 和 WaitUntilFirstFrameRasterized 方法已被棄用並移除,目的是提供一個更具組合性的 waitForCondition API,可用於組合客戶端想要等待的條件。
遷移指南
| 遷移前的程式碼 | 遷移後的程式碼 |
|---|---|
WaitUntilNoTransientCallbacks | WaitForCondition(NoTransientCallbacks()) |
WaitUntilNoPendingFrame | WaitForCondition(NoPendingFrame()) |
WaitUntilFirstFrameRasterized | WaitForCondition(FirstFrameRasterized)) |
參考資料
API 文件
相關問題
相關 PR
時間線
#穩定版本:2.0.0