Deprecated API removed after v1.22
- Summary
- Changes
- CupertinoDialog
- Cupertino navigation bars’ actionsForegroundColor
- CupertinoTextThemeData.brightness
- Pointer events constructed fromHoverEvent
- showDialog uses builder
- Scaffold.resizeToAvoidBottomPadding
- ButtonTheme.bar
- InlineSpan, TextSpan, PlaceholderSpan
- RenderView.scheduleInitialFrame
- Layer.findAll
- BinaryMessages
- Generic methods for BuildContext
- WidgetsBinding.deferFirstFrameReport & WidgetsBinding.allowFirstFrameReport
- WaitUntilNoTransientCallbacks, WaitUntilNoPendingFrame, & WaitUntilFirstFrameRasterized
- Timeline
Summary
In accordance with Flutter’s Deprecation Policy, deprecated APIs that reached end of life after the 1.22 stable release have been removed. This is the first time deprecated APIs have been removed from Flutter, and some of these deprecations predate our migration guide policy.
All affected APIs have been compiled into this primary source to aid in migration. A quick reference sheet is available as well.
A design document and article are available for more context on Flutter’s deprecation policy.
Changes
This section lists the deprecations, listed by the affected class.
CupertinoDialog
Supported by fix tool: IDE fix only.
CupertinoDialog
was deprecated in v0.2.3.
Use CupertinoAlertDialog
or CupertinoPopupSurface
instead.
Migration guide
CupertinoAlertDialog
Code before migration:
CupertinoDialog(child: myWidget);
Code after migration:
CupertinoAlertDialog(content: myWidget);
CupertinoPopupSurface
Code before migration:
CupertinoDialog(child: myWidget);
Code after migration:
CupertinoPopupSurface(child: myWidget);
References
API documentation:
Relevant issues:
Relevant PRs:
actionsForegroundColor
Cupertino navigation bars’ Supported by fix tool: No
CupertinoNavigationBar.actionsForegroundColor
and CupertinoSliverNavigationBar.actionsForegroundColor
were deprecated in v1.1.2.
Setting primaryColor
in your CupertinoTheme
propagates this instead.
To access the primaryColor
,
call CupertinoTheme.of(context).primaryColor
.
Migration guide
Code before migration:
CupertinoNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);
CupertinoSliverNavigationBar(
actionsForegroundColor: CupertinoColors.systemBlue,
);
Code after migration:
CupertinoTheme(
data: CupertinoThemeData(
primaryColor: CupertinoColors.systemBlue
),
child: ...
);
// To access the color from the `CupertinoTheme`
CupertinoTheme.of(context).primaryColor;
References
API documentation:
Relevant issues:
Relevant PRs:
CupertinoTextThemeData.brightness
Supported by fix tool: Yes
CupertinoTextThemeData.brightness
was deprecated in v1.10.14.
This field member was made ineffective at the time of deprecation.
There is no replacement for this
parameter, references should be removed.
Migration guide
Code before migration:
const CupertinoTextThemeData themeData = CupertinoTextThemeData(brightness: Brightness.dark);
themeData.copyWith(brightness: Brightness.light);
Code after migration:
const CupertinoTextThemeData themeData = CupertinoTextThemeData();
themeData.copyWith();
References
API documentation:
Relevant issues:
Relevant PRs:
fromHoverEvent
Pointer events constructed Supported by fix tool: Yes
The fromHoverEvent
constructors for PointerEnterEvent
and PointerExitEvent
were deprecated in v1.4.3.
The fromMouseEvent
constructor should be used instead.
Migration guide
Code before migration:
final PointerEnterEvent enterEvent = PointerEnterEvent.fromHoverEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromHoverEvent(PointerHoverEvent());
Code after migration:
final PointerEnterEvent enterEvent = PointerEnterEvent.fromMouseEvent(PointerHoverEvent());
final PointerExitEvent exitEvent = PointerExitEvent.fromMouseEvent(PointerHoverEvent());
References
API documentation:
Relevant issues:
Relevant PRs:
showDialog
uses builder
Supported by fix tool: Yes
The child
parameter of showDialog
was deprecated in in v0.2.3.
The builder
parameter should be used instead.
Migration guide
Code before migration:
showDialog(child: myWidget);
Code after migration:
showDialog(builder: (context) => myWidget);
References
API documentation:
Relevant issues:
Relevant PRs:
Scaffold.resizeToAvoidBottomPadding
Supported by fix tool: Yes
The resizeToAvoidBottomPadding
parameter of Scaffold
was deprecated in in v1.1.9.
The resizeToAvoidBottomInset
parameter should be used instead.
Migration guide
Code before migration:
Scaffold(resizeToAvoidBottomPadding: true);
Code after migration:
Scaffold(resizeToAvoidBottomInset: true);
References
API documentation:
Relevant issues:
- Show warning when nesting Scaffolds
- SafeArea with keyboard
- Double stacked material scaffolds shouldn’t double resizeToAvoidBottomPadding
- viewInsets and padding on Window and MediaQueryData should define how they interact
- bottom overflow issue, when using textfields inside tabbarview
Relevant PRs:
ButtonTheme.bar
Supported by fix tool: No
The bar
constructor of ButtonTheme
was deprecated in in v1.9.1.
ButtonBarTheme
can be used instead for ButtonBar
s,
or use another constructor of ButtonTheme
if the use is not specific to ButtonBar
.
Button-specific theming is also available with the TextButtonTheme
,
ElevatedButtonTheme
, and OutlinedButtonTheme
classes,
each corresponding with the appropriate button class,
TextButton
, ElevatedButton
and OutlinedButton
.
Migration guide
Code before migration:
ButtonTheme.bar(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);
Code after migration, using ButtonTheme
:
ButtonTheme(
minWidth: 10.0,
alignedDropdown: true,
height: 40.0,
);
Code after migration, using ButtonBarTheme
:
ButtonBarTheme(
data: ButtonBarThemeData(
buttonMinWidth: 10.0,
buttonAlignedDropdown: true,
buttonHeight: 40.0,
)
);
References
API documentation:
ButtonTheme
ButtonBarTheme
ButtonBar
TextButtonTheme
TextButton
ElevatedButtonTheme
ElevatedButton
OutlinedButtonTheme
OutlinedButton
Relevant issues:
- ButtonTheme.bar uses accent color when it should be using primary color
- ThemeData.accentColor has insufficient contrast for text
- Increased height as a result of changes to materialTapTargetSize affecting AlertDialog/ButtonBar heights
Relevant PRs:
InlineSpan
, TextSpan
, PlaceholderSpan
Supported by fix tool: No
The following methods were deprecated in the InlineSpan
, TextSpan
and PlaceholderSpan
in order
to enable embedding widgets inline into paragraphs, like images.
Migration guide
Code before migration | Code after migration |
---|---|
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 |
References
API documentation:
Relevant issues:
Relevant PRs:
RenderView.scheduleInitialFrame
Supported by fix tool: No
The RenderView.scheduleInitialFrame
method was deprecated and removed in order to prevent
splash screens from being taken down too early, resulting in a black screen. This would happen when
WidgetsFlutterBinding.ensureInitialized
was called. Instead, replace calls to this method with
RenderView.prepareInitialFrame
, followed by RenderView.owner.requestVisualUpdate
.
Migration guide
Code before migration:
scheduleInitialFrame();
Code after migration:
prepareInitialFrame();
owner.requestVisualUpdate();
References
API documentation:
Relevant issues:
Relevant PRs:
Layer.findAll
Supported by fix tool: No
The Layer.findAll
method was deprecated with the introduction of Layer.findAnnotations
in order
to unify the implementations of find
and findAll
. To migrate affected code, call
findAllAnnotations
instead. This method returns an AnnotationResult
, containing the former
return value of findAll
in AnnotationResult.annotations
.
Migration guide
Code before migration:
findAll(offset);
Code after migration:
findAllAnnotations(offset).annotations;
References
API documentation:
Relevant issues:
Relevant PRs:
BinaryMessages
Supported by fix tool: No
The BinaryMessages
class, its associated static methods and the defaultBinaryMessenger
getter
were deprecated and removed. The defaultBinaryMessenger
instance was moved to ServicesBinding
.
This made it possible to register a different default BinaryMessenger
under testing environment,
by creating a ServicesBinding
subclass for testing. Doing so allows you to track the number of
pending platform messages for synchronization purposes.
Migration guide
Code before migration: | Code after migration: |
---|---|
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 |
References
API documentation:
Relevant issues:
Relevant PRs:
BuildContext
Generic methods for Supported by fix tool: Yes
Several methods in BuildContext
were using Type
to search for ancestors. Most of those methods
implied a cast at call site because their return type was a parent type. Moreover the type provided
was not checked at analysis time even if the type is actually constrained. Making these methods
generics improves type safety and requires less code.
These method changes affect the BuildContext
, Element
, and StatefulElement
classes. The
TypeMatcher
class was also removed.
Migration guide
Code before migration:
ComplexLayoutState state = context.ancestorStateOfType(const TypeMatcher<ComplexLayoutState>()) as ComplexLayoutState;
Code after migration:
ComplexLayoutState state = context.ancestorStateOfType<ComplexLayoutState>();
BuildContext
Code before migration: | Code after migration: |
---|---|
inheritFromElement |
dependOnInheritedElement |
inheritFromWidgetOfExactType |
dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType |
getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType |
findAncestorWidgetOfExactType |
ancestorStateOfType |
findAncestorStateOfType |
rootAncestorStateOfType |
findRootAncestorStateOfType |
ancestorRenderObjectOfType |
findAncestorRenderObjectOfType |
Element
Code before migration: | Code after migration: |
---|---|
inheritFromElement |
dependOnInheritedElement |
inheritFromWidgetOfExactType |
dependOnInheritedWidgetOfExactType |
ancestorInheritedElementForWidgetOfExactType |
getElementForInheritedWidgetOfExactType |
ancestorWidgetOfExactType |
findAncestorWidgetOfExactType |
ancestorStateOfType |
findAncestorStateOfType |
rootAncestorStateOfType |
findRootAncestorStateOfType |
ancestorRenderObjectOfType |
findAncestorRenderObjectOfType |
StatefulElement
Code before migration: | Code after migration: |
---|---|
inheritFromElement |
dependOnInheritedElement |
References
API documentation:
Relevant PRs:
WidgetsBinding.deferFirstFrameReport
& WidgetsBinding.allowFirstFrameReport
Supported by fix tool: Yes
The deferFirstFrameReport
and allowFirstFrameReport
methods of WidgetsBinding
were deprecated
and removed in order to provide the option to delay rendering the first frame. This is useful for
widgets that need to obtain initialization information asynchronously and while they are waiting for
that information no frame should render as that would take down the splash screen pre-maturely.
The deferFirstFrame
and allowFirstFrame
methods should be used respectively instead.
Migration guide
Code before migration:
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrameReport();
binding.allowFirstFrameReport();
Code after migration:
final WidgetsBinding binding = WidgetsBinding.instance;
binding.deferFirstFrame();
binding.allowFirstFrame();
References
API documentation:
Relevant PRs:
WaitUntilNoTransientCallbacks
, WaitUntilNoPendingFrame
, & WaitUntilFirstFrameRasterized
Supported by fix tool: No
The WaitUntilNoTransientCallbacks
, WaitUntilNoPendingFrame
, and WaitUntilFirstFrameRasterized
methods from the flutter_driver
packages were deprecated and removed in order to provide a more
composable waitForCondition
API that can be used to compose conditions that the client would like
to wait for.
Migration guide
Code before migration: | Code after migration: |
---|---|
WaitUntilNoTransientCallbacks |
WaitForCondition(NoTransientCallbacks()) |
WaitUntilNoPendingFrame |
WaitForCondition(NoPendingFrame()) |
WaitUntilFirstFrameRasterized |
WaitForCondition(FirstFrameRasterized)) |
References
API documentation:
Relevant issues:
Relevant PRs:
Timeline
In stable release: 2.0.0