v3.13 後移除的已棄用 API
摘要
#根據 Flutter 的 棄用政策,在 3.13 穩定版本之後達到生命週期終點的已棄用 API 已被移除。
所有受影響的 API 都已編譯到此主要來源中,以協助遷移。為了進一步協助您的遷移,請查看此快速參考表。
變更
#此章節列出了按套件和受影響類別分類的棄用項目。
Chip 類別的 useDeleteButtonTooltip
#套件:flutter,Flutter Fix 支援:是
下列類別的 useDeleteButtonTooltip
屬性在 v2.10 中被棄用
DeletableChipAttributes
Chip
RawChip
InputChip
deleteButtonTooltipMessage
取代了 useDeleteButtonTooltip
。此變更簡化了 API,因為向 deleteButtonTooltipMessage
提供空字串與將原始屬性 useDeleteButtonTooltip
設定為 false 達到相同的效果。當 deleteButtonTooltipMessage
未設定時,預設會使用 MaterialLocalizations.deleteButtonTooltip
。
棄用 Chip 的 useDeleteButtonTooltip
設計文件更深入地介紹了此晶片和工具提示的更新。若要深入了解,請查看晶片和工具提示遷移指南。
遷移指南
遷移前的程式碼
Chip(useDeleteButtonTooltip: false);
InputChip(useDeleteButtonTooltip: true);
RawChip rawChip = RawChip();
rawChip.useDeleteButtonTooltip;
遷移後的程式碼
Chip(deleteButtonTooltipMessage: '');
InputChip();
RawChip rawChip = RawChip();
rawChip.deleteButtonTooltipMessage;
參考資料
API 文件
相關 PR
MaterialButtonWithIconMixin
#套件:flutter,Flutter Fix 支援:否
MaterialButtonWithIconMixin
屬性在 v2.11 中被棄用。
隨著新按鈕類別 TextButton
、OutlinedButton
和 ElevatedButton
的推出,不再使用此 mixin。先前的版本已移除使用此 mixin 的舊按鈕類別。因此,此 mixin 不再影響任何可能混合使用它的類別。
遷移指南
遷移前的程式碼
class MyButtonClass extends StatelessWidget with MaterialButtonWithIconMixin {
// ...
}
遷移後的程式碼
class MyButtonClass extends StatelessWidget {
// ...
}
參考資料
相關 PR
PlatformsViewsService.synchronizeToNativeViewHierarchy
#套件:flutter,Flutter Fix 支援:否
PlatformsViewsService
的靜態方法 synchronizeToNativeViewHierarchy
在 v2.11 中被棄用。
在棄用期間,該方法是一個無操作函數,因為不再需要呼叫它以提高效能。應移除對該方法的引用,且不會影響應用程式。
遷移指南
遷移前的程式碼
await PlatformsViewsService.synchronizeToNativeViewHierarchy(false);
遷移後的程式碼
參考資料
API 文件
相關 PR
TextSelectionOverlay.fadeDuration
#套件:flutter,Flutter Fix 支援:是
TextSelectionOverlay
的靜態 fadeDuration
屬性在 v2.12 中被棄用。
SelectionOverlay.fadeDuration
屬性取代了 TextSelectionOverlay.fadeDuration
。隨著 TextSelectionOverlay
的重構,SelectionOverlay
被新增為一個更通用的 widget,而沒有對 RenderEditable
的特定依賴。
遷移指南
遷移前的程式碼
TextSelectionOverlay.fadeDuration;
遷移後的程式碼
SelectionOverlay.fadeDuration;
參考資料
API 文件
相關 PR
androidOverscrollIndicator
#套件:flutter,Flutter Fix 支援:否
下列類別的 androidOverscrollIndicator
屬性在 v2.13 中被棄用
ScrollBehavior
MaterialScrollBehavior
ThemeData
引入此標誌是為了允許使用者配置滾動 widget 以使用 GlowingOverscrollIndicator
或 StretchingOvercrollIndicator
。它被棄用,改用 ThemeData.useMaterial3
標誌,因為框架引入了更多對 Material 3 風格 widget 的支援。
由於 ThemeData.useMaterial3
預設為 true
,因此預設會套用 StretchingOverscrollIndicator
。將此值設定為 false
將改為套用 GlowingOverscrollIndicator
。
或者,可以覆寫 ScrollBehavior
或 MaterialScrollBehavior
的 buildOverscrollIndicator
方法,以進一步變更過度滾動指示器的外觀。
遷移指南
遷移前的程式碼
MaterialApp(
scrollBehavior: MaterialScrollBehavior(
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
),
//...
);
MaterialApp(
scrollBehavior: ScrollBehavior(
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
),
//...
);
MaterialApp(
theme: Theme.light().copyWith(
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
),
//...
);
遷移後的程式碼
MaterialApp(
theme: Theme.light().copyWith(
// defaults to true and stretching indicator,
// false results in glowing indicator
useMaterial3: false,
),
//...
);
參考資料
API 文件
ScrollBehavior
MaterialScrollBehavior
ThemeData
GlowingOverscrollIndicator
StretchingOverscrollIndicator
相關 PR
ImageProvider 和 PaintingBinding 的更新
#套件:flutter,Flutter Fix 支援:否
PaintingBinding
的 instantiateImageCodec
方法,以及 ImageProvider
的 load
方法和相關的 DecoderCallback
皆在 v2.13 中被棄用。
各自的替代方法是
已棄用的方法 | 目前的方法 |
---|---|
PaintingBinding.instantiateImageCodec | PaintingBinding.instantiateImageCodecFromBuffer |
ImageProvider.load | ImageProvider.loadBuffer |
DecoderCallback | DecoderBufferCallback |
此變更透過使用緩衝區實現了更快的影像載入效能。
遷移指南
遷移前的程式碼
PaintingBinding.instance.instantiateImageCodec
遷移後的程式碼
PaintingBinding.instance.instantiateImageCodecFromBuffer
參考資料
API 文件
相關 PR
TestWindow 屬性
#套件:flutter_test,Flutter Fix 支援:否
為了準備支援多視窗,已移除 TestWindow
的許多已棄用屬性。雖然 TestWindow
已被棄用,但目前不符合移除的條件。立即遷移過期的屬性將有助於從 TestWindow
進行遷移。
已移除下列屬性
localeTestValue
clearLocaleTestValue
localesTestValue
clearLocalesTestValue
initialLifecycleStateTestValue
textScaleFactorTestValue
clearTextScaleFactorTestValue
platformBrightnessTestValue
clearPlatformBrightnessTestValue
alwaysUse24HourFormatTestValue
clearAlwaysUse24HourTestValue
brieflyShowPasswordTestValue
defaultRouteNameTestValue
clearDefaultRouteNameTestValue
semanticsEnabledTestValue
clearSemanticsEnabledTestValue
accessibilityFeaturesTestValue
clearAccessibilityFeaturesTestValue
若要深入了解此 TestWindow
更新,請查看TestWindow
遷移指南。
遷移指南
遷移前的程式碼
testWidgets('My test', (WidgetTester tester) aysnc {
// For all instances, replace window with platformDispatcher
tester.binding.window.textScaleFactorTestValue = 42;
addTearDown(tester.binding.window.clearTextScaleFactorTestValue);
// ...
});
遷移後的程式碼
testWidgets('My test', (WidgetTester tester) aysnc {
// For all instances, replace window with platformDispatcher
tester.binding.platformDispatcher.textScaleFactorTestValue = 42;
addTearDown(tester.binding.platformDispatcher.clearTextScaleFactorTestValue);
// ...
});
參考資料
API 文件
相關 PR
時間軸
#在穩定版本中:3.16
除非另有說明,否則本網站上的文件反映了 Flutter 的最新穩定版本。頁面最後更新於 2024-06-01。 檢視原始碼 或 回報問題。