v1.22 後移除的已棄用 API
- 摘要
- 變更
- CupertinoDialog
- Cupertino 導覽列的 actionsForegroundColor
- CupertinoTextThemeData.brightness
- 從 HoverEvent 建構的指標事件
- showDialog 使用 builder
- Scaffold.resizeToAvoidBottomPadding
- ButtonTheme.bar
- InlineSpan、TextSpan、PlaceholderSpan
- RenderView.scheduleInitialFrame
- Layer.findAll
- BinaryMessages
- BuildContext 的泛型方法
- WidgetsBinding.deferFirstFrameReport & WidgetsBinding.allowFirstFrameReport
- WaitUntilNoTransientCallbacks、WaitUntilNoPendingFrame、& WaitUntilFirstFrameRasterized
- 時間軸
摘要
#根據 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
建構的指標事件
#修復工具支援:是
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
- 雙堆疊材質 Scaffold 不應重複 resizeToAvoidBottomPadding
- Window 和 MediaQueryData 上的 viewInsets 和 padding 應定義它們如何互動
- 在 tabbarview 中使用 textfield 時的底部溢位問題
相關的 PR
ButtonTheme.bar
#修復工具支援:否
ButtonTheme
的 bar
建構函式在 v1.9.1 中已棄用。ButtonBarTheme
可用於 ButtonBar
,或者如果使用不特定於 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 文件
ButtonTheme
ButtonBarTheme
ButtonBar
TextButtonTheme
TextButton
ElevatedButtonTheme
ElevatedButton
OutlinedButtonTheme
OutlinedButton
相關問題
- ButtonTheme.bar 在應該使用 primary color 時使用 accent color
- ThemeData.accentColor 對於文字的對比度不足
- 由於 materialTapTargetSize 的變更影響 AlertDialog/ButtonBar 高度而導致的高度增加
相關的 PR
InlineSpan
、TextSpan
、PlaceholderSpan
#修復工具支援:否
為了能夠將小工具內嵌到段落中(如圖片),已棄用 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
#修復工具支援:否
為了統一 find
和 findAll
的實作,在引入 Layer.findAnnotations
時,Layer.findAll
方法已棄用。若要遷移受影響的程式碼,請改為呼叫 findAllAnnotations
。此方法會傳回 AnnotationResult
,其中包含 AnnotationResult.annotations
中 findAll
的先前傳回值。
遷移指南
遷移前的程式碼
findAll(offset);
遷移後的程式碼
findAllAnnotations(offset).annotations;
參考資料
API 文件
相關問題
相關的 PR
BinaryMessages
#修復工具支援:否
BinaryMessages
類別、其相關的靜態方法和 defaultBinaryMessenger
getter 已棄用並移除。defaultBinaryMessenger
執行個體已移至 ServicesBinding
。這使得在測試環境下,可以透過為測試建立 ServicesBinding
子類別來註冊不同的預設 BinaryMessenger
。這樣做可讓您追蹤用於同步目的的擱置中平台訊息數量。
遷移指南
遷移前的程式碼 | 遷移後的程式碼 |
---|---|
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
#修復工具支援:否
為了提供一個更可組合的 waitForCondition
API,可用於組合客戶端想要等待的條件,flutter_driver
套件中的 WaitUntilNoTransientCallbacks
、WaitUntilNoPendingFrame
和 WaitUntilFirstFrameRasterized
方法已被棄用並移除。
遷移指南
遷移前的程式碼 | 遷移後的程式碼 |
---|---|
WaitUntilNoTransientCallbacks | WaitForCondition(NoTransientCallbacks()) |
WaitUntilNoPendingFrame | WaitForCondition(NoPendingFrame()) |
WaitUntilFirstFrameRasterized | WaitForCondition(FirstFrameRasterized)) |
參考資料
API 文件
相關問題
相關的 PR
時間軸
#穩定版本:2.0.0
除非另有說明,本網站上的文件反映了 Flutter 的最新穩定版本。頁面最後更新於 2024-06-01。 檢視原始碼 或 回報問題。