v3.13 後移除的已棄用 API
概述
#根據 Flutter 的棄用策略,在 3.13 穩定版釋出後生命週期結束的已棄用 API 已被移除。
所有受影響的 API 都已整理到此主要來源,以協助遷移。為了進一步協助您遷移,請檢視此快速參考表。
變更
#本節按軟體包和受影響的類列出了廢棄項。
Chip 類中的 useDeleteButtonTooltip
#軟體包:flutter Flutter Fix 支援:是
以下類的 useDeleteButtonTooltip 屬性在 v2.10 中已棄用
DeletableChipAttributesChipRawChipInputChip
deleteButtonTooltipMessage 替換了 useDeleteButtonTooltip。此更改簡化了 API,因為向 deleteButtonTooltipMessage 提供一個空字串可以達到與將原始屬性 useDeleteButtonTooltip 設定為 false 相同的結果。當 deleteButtonTooltipMessage 未設定時,預設使用 MaterialLocalizations.deleteButtonTooltip。
《棄用 Chip 的 useDeleteButtonTooltip》設計文件更深入地介紹了此對 Chip 和 Tooltip 的更新。要了解更多資訊,請檢視Chip 和 Tooltip 遷移指南。
遷移指南
遷移前的程式碼
Chip(useDeleteButtonTooltip: false);
InputChip(useDeleteButtonTooltip: true);
RawChip rawChip = RawChip();
rawChip.useDeleteButtonTooltip;遷移後的程式碼
Chip(deleteButtonTooltipMessage: '');
InputChip();
RawChip rawChip = RawChip();
rawChip.deleteButtonTooltipMessage;參考資料
API 文件
相關 PR
MaterialButtonWithIconMixin
#Package: 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
#Package: 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
#Package: flutter 受 Flutter Fix 支援: 否
以下類的 androidOverscrollIndicator 屬性在 v2.13 中已棄用
ScrollBehaviorMaterialScrollBehaviorThemeData
此標誌的引入是為了允許使用者配置滾動 Widget 使用 GlowingOverscrollIndicator 或 StretchingOvercrollIndicator。由於框架為 Material 3 風格的 Widget 提供了更多支援,它已被 ThemeData.useMaterial3 標誌取代。
由於 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 文件
ScrollBehaviorMaterialScrollBehaviorThemeDataGlowingOverscrollIndicatorStretchingOverscrollIndicator
相關 PR
ImageProvider 和 PaintingBinding 的更新
#Package: 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 屬性
#Package: flutter_test 受 Flutter Fix 支援: 否
為了支援多視窗功能,TestWindow 的許多已棄用屬性已被移除。雖然 TestWindow 已被棄用,但目前還不符合移除條件。現在遷移過期的屬性將有助於從 TestWindow 遷移。
已移除的屬性如下:
localeTestValueclearLocaleTestValuelocalesTestValueclearLocalesTestValueinitialLifecycleStateTestValuetextScaleFactorTestValueclearTextScaleFactorTestValueplatformBrightnessTestValueclearPlatformBrightnessTestValuealwaysUse24HourFormatTestValueclearAlwaysUse24HourTestValuebrieflyShowPasswordTestValuedefaultRouteNameTestValueclearDefaultRouteNameTestValuesemanticsEnabledTestValueclearSemanticsEnabledTestValueaccessibilityFeaturesTestValueclearAccessibilityFeaturesTestValue
要了解此 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