Deprecated API removed after v3.16
Summary
#In accordance with Flutter's Deprecation Policy, deprecated APIs that reached end of life after the 3.16 stable release have been removed.
All affected APIs have been compiled into this primary source to aid in migration. To further aid your migration, check out this quick reference sheet.
Changes
#This section lists the deprecations by the package and affected class.
Button styleFrom
properties
#Package: flutter Supported by Flutter Fix: yes
The TextButton
, ElevatedButton
and OutlinedButton
widgets all have a
static styleFrom
method for generating the ButtonStyle
. The following color
properties of this method for each class were deprecated in v3.1:
TextButton.styleFrom
primary
onSurface
ElevatedButton.styleFrom
primary
onPrimary
onSurface
OutlinedButton.styleFrom
primary
onSurface
These changes better aligned the API with updated Material Design
specifications. The changes also provided more clarity in how the colors would
be applied to the buttons, by replacing these properties with backgroundColor
,
foregroundColor
, and disabledForegroundColor
.
Migration guide
Code before migration:
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,
);
Code after migration:
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,
);
References
API documentation:
Relevant PRs:
ThemeData.selectedRowColor
#Package: flutter Supported by Flutter Fix: yes
The selectedRowColor
property of ThemeData
was deprecated in v3.1.
The property was no longer used by the framework, as widgets using it migrated to other component themes or no longer required it in the updated specification for Material Design.
Migration guide
Code before migration:
ThemeData(
// ...
selectedRowColor: Colors.pink, // Would have no effect.
);
Code after migration:
ThemeData(
// ...
// Remove uses.
);
References
API documentation:
Relevant PRs:
NavigatorState.focusScopeNode
#Package: flutter Supported by Flutter Fix: yes
The focusScopeNode
property of NavigatorState
was deprecated in v3.1.
This change was made to resolve several issues stemming around the
FocusScopeNode
introduced by the Navigator
. Instead, the FocusScope
was moved to enclose the topmost Navigator
in a WidgetsApp
.
NavigatorState
was changed to contain its own FocusNode
, from where it can
refer to its FocusNode.enclosingScope
to access the correct FocusScopeNode
.
Migration guide
Code before migration:
Navigator.of(context).focusScopeNode;
Code after migration:
Navigator.of(context).focusNode.enclosingScope!;
References
API documentation:
Relevant PRs:
PlatformMenuBar.body
#Package: flutter Supported by Flutter Fix: yes
The body
property of PlatformMenuBar
was deprecated in v3.1.
This change was made to align PlatformMenuBar
with other widgets in the
framework, renaming it to child
.
Migration guide
Code before migration:
PlatformMenuBar(
body: myWidget,
);
Code after migration:
PlatformMenuBar(
child: myWidget,
);
References
API documentation:
Relevant PRs:
The previously announced deprecations for TextTheme
, WidgetInspectorService
,
and WidgetInspectorServiceExtensions
were not removed during this cycle.
The WidgetInspectorService
and WidgetInspectorServiceExtensions
deprecation on setPubRootDirectories
has been extended another year to allow
IDEs and other customer to migrate.
Expect the TextTheme
deprecations to be removed in the next cycle, which will
be announced again when it comes.
Timeline
#除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-06-01。 查看文档源码 或者 为本页面内容提出建议。