id
stringlengths 14
17
| text
stringlengths 23
1.11k
| source
stringlengths 35
114
|
---|---|---|
77d302948264-0 | Deprecated API removed after v3.3
Summary
Changes
RenderUnconstrainedBox
DragAnchor, Draggable.dragAnchor & LongPressDraggable.dragAnchor
ScrollBehavior.buildViewportChrome
Timeline
Summary
In accordance with Flutter’s Deprecation Policy,
deprecated APIs that reached end of life after the
3.3 stable release have been removed.
All affected APIs have been compiled into this
primary source to aid in migration. A
quick reference sheet is available as well.
Changes
This section lists the deprecations, listed by the affected class.
RenderUnconstrainedBox
Supported by Flutter Fix: no
RenderUnconstrainedBox was deprecated in v2.1.
Use RenderConstraintsTransformBox instead.
Where unconstrained in both axes, provide ConstraintsTransformBox.unconstrained
to constraintsTransform. | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-1 | If RenderUnconstrainedBox.constrainedAxis was previously set, replace respectively:
Where constrainedAxis was previously Axis.horizontal, set
constraintsTransform to ConstraintsTransformBox.widthUnconstrained
Where constrainedAxis was previously Axis.vertical, set
constraintsTransform to ConstraintsTransformBox.heightUnconstrained
This change allowed for the introduction of several more types of constraint
transformations through ConstraintsTransformBox. Other parameters of the old
API are compatible with the new API.
Migration guide
Code before migration:
// Unconstrained
final
RenderUnconstrainedBox
unconstrained
RenderUnconstrainedBox
textDirection:
TextDirection
ltr
child:
RenderConstrainedBox
additionalConstraints:
const
BoxConstraints
tightFor | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-2 | const
BoxConstraints
tightFor
height:
200.0
),
),
alignment:
Alignment
center
);
// Constrained in horizontal axis
final
RenderUnconstrainedBox
unconstrained
RenderUnconstrainedBox
constrainedAxis:
Axis
horizontal
textDirection:
TextDirection
ltr
child:
RenderConstrainedBox
additionalConstraints:
const
BoxConstraints
tightFor
width:
200.0
height:
200.0
), | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-3 | height:
200.0
),
),
alignment:
Alignment
center
);
// Constrained in vertical axis
final
RenderUnconstrainedBox
unconstrained
RenderUnconstrainedBox
constrainedAxis:
Axis
vertical
textDirection:
TextDirection
ltr
child:
RenderFlex
direction:
Axis
vertical
textDirection:
TextDirection
ltr
children:
RenderBox
>[
flexible
],
),
alignment: | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-4 | ],
),
alignment:
Alignment
center
);
Code after migration:
// Unconstrained
final
RenderConstraintsTransformBox
unconstrained
RenderConstraintsTransformBox
constraintsTransform:
ConstraintsTransformBox
unconstrained
textDirection:
TextDirection
ltr
child:
RenderConstrainedBox
additionalConstraints:
const
BoxConstraints
tightFor
height:
200.0
),
),
alignment:
Alignment
center
);
// Constrained in horizontal axis
final | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-5 | );
// Constrained in horizontal axis
final
RenderConstraintsTransformBox
unconstrained
RenderConstraintsTransformBox
constraintsTransform:
ConstraintsTransformBox
widthUnconstrained
textDirection:
TextDirection
ltr
child:
RenderConstrainedBox
additionalConstraints:
const
BoxConstraints
tightFor
width:
200.0
height:
200.0
),
),
alignment:
Alignment
center
);
// Constrained in vertical axis
final
RenderConstraintsTransformBox
unconstrained | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-6 | final
RenderConstraintsTransformBox
unconstrained
RenderConstraintsTransformBox
constraintsTransform:
ConstraintsTransformBox
widthUnconstrained
textDirection:
TextDirection
ltr
child:
RenderFlex
direction:
Axis
vertical
textDirection:
TextDirection
ltr
children:
RenderBox
>[
flexible
],
),
alignment:
Alignment
center
);
References
API documentation:
RenderConstraintsTransformBox
ConstraintsTransformBox
Relevant PRs: | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-7 | ConstraintsTransformBox
Relevant PRs:
Deprecated in #78673
Removed in #111711
DragAnchor, Draggable.dragAnchor & LongPressDraggable.dragAnchor
Supported by Flutter Fix: yes
The enum DragAnchor, and its uses in Draggable.dragAnchor &
LongPressDraggable.dragAnchor were deprecated in v2.1.
Use dragAnchorStrategy instead.
This change allowed for more accurate feedback of the draggable widget when used
in conjunction with other widgets like Stack and InteractiveViewer.
Migration guide
Code before migration:
Draggable
draggable
Draggable
();
draggable
Draggable
dragAnchor:
DragAnchor
child
);
draggable | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-8 | child
);
draggable
Draggable
dragAnchor:
DragAnchor
pointer
);
LongPressDraggable
longPressDraggable
LongPressDraggable
();
longPressDraggable
LongPressDraggable
dragAnchor:
DragAnchor
child
);
longPressDraggable
LongPressDraggable
dragAnchor:
DragAnchor
pointer
);
Code after migration:
Draggable
draggable
Draggable
();
draggable
Draggable
dragAnchorStrategy:
childDragAnchorStrategy
); | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-9 | dragAnchorStrategy:
childDragAnchorStrategy
);
draggable
Draggable
dragAnchorStrategy:
pointerDragAnchorStrategy
);
LongPressDraggable
longPressDraggable
LongPressDraggable
();
longPressDraggable
LongPressDraggable
dragAnchorStrategy:
childDragAnchorStrategy
);
longPressDraggable
LongPressDraggable
dragAnchorStrategy:
pointerDragAnchorStrategy
);
References
API documentation:
Draggable
LongPressDraggable
DragAnchorStrategy
Relevant issues:
#73143
Relevant PRs: | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-10 | #73143
Relevant PRs:
Deprecated in #79160
Removed in #111713
ScrollBehavior.buildViewportChrome
Supported by Flutter Fix: yes
The method ScrollBehavior.buildViewportChrome was deprecated in v2.1.
This method was used by the Scrollable widget to apply an overscroll
indicator, like GlowingOverscrollIndicator, by default on the appropriate
platforms. As more default decorators have been added, like Scrollbars, each
has instead been split into individual methods to replace buildViewportChrome.
This allows extending classes to only override the specific decorator, through
buildScrollbar or buildOverscrollIndicator, rather than needing to rewrite
code in order to maintain one or the other.
Migration guide
In-depth migration guide available
Code before migration: | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-11 | In-depth migration guide available
Code before migration:
final
ScrollBehavior
scrollBehavior
ScrollBehavior
();
scrollBehavior
buildViewportChrome
context
child
axisDirection
);
Code after migration:
final
ScrollBehavior
scrollBehavior
ScrollBehavior
();
scrollBehavior
buildOverscrollIndicator
context
child
axisDirection
);
References
Design document:
Exposing & Updating ScrollBehaviors
API documentation:
ScrollBehavior
Relevant issues:
Scrollbars should be always visible and instantiated by default on web and desktop | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
77d302948264-12 | Scrollbars should be always visible and instantiated by default on web and desktop
Relevant PRs:
#76739
Deprecated in #78588
Removed in #111715
Timeline
In stable release: 3.7 | https://docs.flutter.dev/release/breaking-changes/3-3-deprecations/index.html |
e8b632cdbd9c-0 | Deprecated API removed after v3.7
Summary
Changes
GestureRecognizer.kind & subclasses
ThemeData accentColor, accentColorBrightness, accentColorTextTheme, accentColorIconTheme, and buttonColor
AppBar, SliverAppBar, and AppBarTheme updates
SystemChrome.setEnabledSystemUIOverlays
SystemNavigator.routeUpdated
AnimatedSize.vsync
Timeline
Summary
In accordance with Flutter’s Deprecation Policy,
deprecated APIs that reached end of life after the
3.7 stable release have been removed.
All affected APIs have been compiled into this
primary source to aid in migration. A
quick reference sheet is available as well.
Changes
This section lists the deprecations, listed by the affected class.
GestureRecognizer.kind & subclasses
Supported by Flutter Fix: yes | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-1 | Supported by Flutter Fix: yes
GestureRecognizer.kind was deprecated in v2.3.
Use GestureRecognizer.supportedDevices instead.
This same change affects all subclasses of GestureRecognizer:
EagerGestureRecognizer
ForcePressGestureRecognizer
LongPressGestureRecognizer
DragGestureRecognizer
VerticalDragGestureRecognizer
HorizontalDragGestureRecognizer
MultiDragGestureRecognizer
ImmediateMultiDragGestureRecognizer
HorizontalMultiDragGestureRecognizer
VerticalMultiDragGestureRecognizer
DelayedMultiDragGestureRecognizer
DoubleTapGestureRecognizer
MultiTapGestureRecognizer
OneSequenceGestureRecognizer
PrimaryPointerGestureRecognizer
ScaleGestureRecognizer
This change allowed for multiple devices to be recognized for a gesture, rather
than the single option kind provided.
Migration guide | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-2 | Migration guide
Code before migration:
var
myRecognizer
GestureRecognizer
kind:
PointerDeviceKind
mouse
);
Code after migration:
var
myRecognizer
GestureRecognizer
supportedDevices:
PointerDeviceKind
>[
PointerDeviceKind
mouse
],
);
References
API documentation:
GestureRecognizer
EagerGestureRecognizer
ForcePressGestureRecognizer
LongPressGestureRecognizer
DragGestureRecognizer
VerticalDragGestureRecognizer
HorizontalDragGestureRecognizer
MultiDragGestureRecognizer
ImmediateMultiDragGestureRecognizer | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-3 | MultiDragGestureRecognizer
ImmediateMultiDragGestureRecognizer
HorizontalMultiDragGestureRecognizer
VerticalMultiDragGestureRecognizer
DelayedMultiDragGestureRecognizer
DoubleTapGestureRecognizer
MultiTapGestureRecognizer
OneSequenceGestureRecognizer
PrimaryPointerGestureRecognizer
ScaleGestureRecognizer
Relevant PRs:
Deprecated in #81858
Removed in #119572
Supported by Flutter Fix: yes
This change better aligned ThemeData with Material Design guidelines. It also
created more clarity in theming by relying either on the core color scheme or
individual component themes for desired styling.
The accentColorBrightness, accentColorTextTheme,
accentColorIconTheme, and buttonColor are no longer used by the framework.
References should be removed. | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-4 | Uses of ThemeData.accentColor should be replaced with
ThemeData.colorScheme.secondary.
Migration guide
Code before migration:
var
myTheme
ThemeData
//...
accentColor:
Colors
blue
//...
);
var
color
myTheme
accentColor
Code after migration:
var
myTheme
ThemeData
//...
colorScheme:
ColorScheme
//...
secondary:
Colors
blue
//...
),
//...
);
var
color | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-5 | );
var
color
myTheme
colorScheme
secondary
References
In-depth migration guide
Accent color migration guide
API documentation:
ThemeData
ColorScheme
Relevant issues:
#56639
#84748
#56918
#91772
Relevant PRs:
Deprecated in:
#92822
#81336
#85144
Removed in:
#118658
#119360
#120577
#120932 | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-6 | #120577
#120932
AppBar, SliverAppBar, and AppBarTheme updates
Supported by Flutter Fix: yes
In v2.4, several changes were made ot the app bar classes and their themes to
better align with Material Design. Several properties were deprecated at that
time and have been removed.
For AppBar, SliverAppBar and AppBarTheme:
brightness has been removed, and is replaced by systemOverlayStyle
textTheme has been removed, and is replaced by either toolbarTextStyle or titleTextStyle.
backwardsCompatibility can be removed, as it was a temporary migration flag for these properties.
Additionally, AppBarTheme.color was removed, with AppBarTheme.backgroundColor
as its replacement.
Migration guide
Code before migration:
var
toolbarTextStyle
TextStyle | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-7 | var
toolbarTextStyle
TextStyle
(...);
var
titleTextStyle
TextStyle
(...);
AppBar
brightness:
Brightness
light
textTheme:
TextTheme
bodyMedium:
toolbarTextStyle
titleLarge:
titleTextStyle
backwardsCompatibility:
true
);
AppBarTheme
color:
Colors
blue
);
Code after migration:
var
toolbarTextStyle
TextStyle
(...);
var
titleTextStyle
TextStyle | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-8 | var
titleTextStyle
TextStyle
(...);
AppBar
systemOverlayStyle:
SystemOverlayStyle
statusBarBrightness:
Brightness
light
),
toolbarTextStyle:
toolbarTextStyle
titleTextStyle:
titleTextStyle
);
AppBarTheme
backgroundColor:
Colors
blue
);
References
API documentation:
AppBar
SliverAppBar
AppBarTheme
Relevant issues:
#86127
#70645
#67921
#67497 | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-9 | #67921
#67497
#50606
#51820
#61618
Deprecated in:
#86198
#71184
Removed in:
#120618
#119253
#120575
SystemChrome.setEnabledSystemUIOverlays
Supported by Flutter Fix: yes
In v2.3, SystemChrome.setEnabledSystemUIOVerlays, the static method for
setting device system level overlays like status and navigation bars, was
deprecated in favor of SystemChrome.setEnabledSystemUIMode.
This change allowed for setting up common fullscreen modes that match native
Android app designs like edge to edge. | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-10 | Manually setting overlays, instead of choosing a specific mode, is still
supported through SystemUiMode.manual, allowing developers to pass the same
list of overlays as before.
Migration guide
Code before migration:
SystemChrome
setEnabledSystemUIOverlays
(<
SystemUiOverlay
>[
SystemUiOverlay
top
SystemUiOverlay
bottom
]);
Code after migration:
SystemChrome
setEnabledSystemUIMode
SystemUiMode
manual
overlays:
SystemUiOverlay
>[
SystemUiOverlay
top
SystemUiOverlay
bottom
], | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-11 | SystemUiOverlay
bottom
],
);
References
API documentation:
SystemChrome
Relevant issues:
#35748
#40974
#44033
#63761
#69999
Deprecated in:
#81303
Removed in:
#11957
SystemNavigator.routeUpdated
Supported by Flutter Fix: yes
In v2.3, SystemNavigator.routeUpdated was deprecated in favor of
SystemNavigator.routeInformationUpdated. | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-12 | Instead of having two ways to update the engine about the current route, the
change moved everything to one API, which separately selects the single-entry
history mode if a Navigator that reports routes is created.
Migration guide
Code before migration:
SystemNavigator
routeUpdated
routeName:
'foo'
previousRouteName:
'bar'
);
Code after migration:
SystemNavigator
routeInformationUpdated
location:
'foo'
);
References
API documentation:
SystemNavigator
Relevant issues:
#82574
Deprecated in:
#82594
Removed in:
#119187 | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-13 | Removed in:
#119187
AnimatedSize.vsync
Supported by Flutter Fix: yes
In v2.2, AnimatedSize.vsyc was deprecated. This property was no longer
necessary after AnimatedSize was converted to a StatefulWidget whose State
mixed in SingleTickerProviderStateMixin. The change was made to fix a memory
leak.
Uses of vsync should be removed, as AnimatedSize now handles this property.
Migration guide
Code before migration:
AnimatedSize
vsync:
this
// ...
);
Code after migration:
AnimatedSize
// ...
);
References
API documentation:
AnimatedSize
Deprecated in: | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
e8b632cdbd9c-14 | AnimatedSize
Deprecated in:
#80554
#81067
Removed in:
#119186
Timeline
In stable release: TBD | https://docs.flutter.dev/release/breaking-changes/3-7-deprecations/index.html |
9d40044d2529-0 | Actions API revision
Summary
Context
Description of change
Example analyzer failures
Migration guide
Actions mapping for pre-defined actions
Custom actions
Custom Actions and Intents with arguments
Timeline
References
Summary
In Flutter an Intent is an object that’s typically bound
to a keyboard key combination using the Shortcuts widget.
An Intent can be bound to an Action,
which can update the application’s state or perform other operations.
In the course of using this API, we identified several drawbacks
in the design, so we have updated the Actions API to make it easier
to use and understand.
LocalKey to an
Context | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-1 | LocalKey to an
Context
The original Actions API design was oriented towards invoking actions from
widgets, and having those actions act in the context of the widget.
Teams have been using actions, and found several limitations in that
design that needed to be addressed:
Actions couldn’t be invoked from outside of the widget hierarchy.
Examples of this include processing a script of commands,
some undo architectures, and some controller architectures.
The mapping from shortcut key to Intent and then to
Action wasn’t always clear, since the data structures
mapped LogicalKeySet =>Intent and then
LocalKey => ActionFactory. The new mapping is still
LogicalKeySet to Intent but then it maps Type
(Intent type) to Action, which is more direct and
readable, since the type of the intent is written in the mapping. | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-2 | If the key binding for an action was in another part of the
widget hierarchy, it was not always possible for the Intent
to have access to the state necessary to decide if the
intent/action should be enabled or not.
The majority of these changes were made in the PRs for
Revise Action API and Make Action.enabled be
isEnabled(Intent intent) instead, and are
described in detail in the design
doc.
Description of change
Here are the changes made to address the above problems:
The Map<LocalKey, ActionFactory> that was given to the Actions widget
is now a Map<Type, Action<Intent>> (the type is the type of the Intent to
be passed to the Action).
The isEnabled method was moved from the Intent class to the Action
class.
The FocusNode argument to Action.invoke and Actions.invoke methods was removed.
Invoking an action no longer creates a new instance of the Action. | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-3 | Invoking an action no longer creates a new instance of the Action.
The LocalKey argument to the Intent constructor was removed.
The LocalKey argument to CallbackAction was removed.
The Action class is now a generic (Action<T extends Intent>) for better
type safety.
The OnInvokeCallback used by CallbackAction no longer takes a FocusNode
argument.
The ActionDispatcher.invokeAction signature has changed to not accept an
optional FocusNode, but instead take an optional BuildContext.
The LocalKey static constants (named key by convention) in Action
subclasses have been removed.
The Action.invoke and ActionDispatcher.invokeAction methods now return
the result of invoking the action as an Object.
The Action class may now be listened to for state changes.
The ActionFactory typedef has been removed, as it is no longer used.
Example analyzer failures | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-4 | Example analyzer failures
Here are some example analyzer failures that might be encountered where an
outdated use of the Actions API might be the cause of the problem. The specifics
of the error might differ, and there may be other failures caused by these
changes.
Migration guide
Significant changes area required to update existing code
to the new API.
Actions mapping for pre-defined actions
To update the action maps in the Actions widget for
predefined actions in Flutter, like ActivateAction
and SelectAction, do the following:
Update the argument type of the actions argument
Use an instance of a specific Intent class in the
Shortcuts mapping, rather than an Intent(TheAction.key)
instance.
Code before migration:
class
MyWidget
extends
StatelessWidget
// ...
@override
Widget | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-5 | // ...
@override
Widget
build
BuildContext
context
return
Shortcuts
shortcuts:
LogicalKeySet
Intent
LogicalKeySet
LogicalKeyboardKey
enter
Intent
ActivateAction
key
),
},
child:
Actions
actions:
LocalKey
ActionFactory
>{
Activate
key
()
ActivateAction
(),
},
child:
Container
(),
);
Code after migration: | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-6 | (),
);
Code after migration:
class
MyWidget
extends
StatelessWidget
// ...
@override
Widget
build
BuildContext
context
return
Shortcuts
shortcuts:
LogicalKeySet
Intent
LogicalKeySet
LogicalKeyboardKey
enter
ActivateIntent
},
child:
Actions
actions:
Type
Action
Intent
>>{
ActivateIntent:
ActivateAction
(),
},
child:
Container | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-7 | },
child:
Container
(),
);
Custom actions
To migrate your custom actions, eliminate the LocalKeys
you’ve defined, and replace them with Intent subclasses,
as well as changing the type of the argument to the actions
argument of the Actions widget.
Code before migration:
class
MyAction
extends
Action
MyAction
()
super
key
);
/// The [LocalKey] that uniquely identifies this action to an [Intent].
static
const
LocalKey
key
ValueKey
Type
>(
RequestFocusAction
);
@override
void | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-8 | );
@override
void
invoke
FocusNode
node
MyIntent
intent
// ...
class
MyWidget
extends
StatelessWidget
// ...
@override
Widget
build
BuildContext
context
return
Shortcuts
shortcuts:
LogicalKeySet
Intent
LogicalKeySet
LogicalKeyboardKey
enter
Intent
MyAction
key
),
},
child:
Actions
actions:
LocalKey
ActionFactory | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-9 | actions:
LocalKey
ActionFactory
>{
MyAction
key
()
MyAction
(),
},
child:
Container
(),
);
Code after migration:
// You may need to create new Intent subclasses if you used
// a bare LocalKey before.
class
MyIntent
extends
Intent
const
MyIntent
();
class
MyAction
extends
Action
MyIntent
@override
Object
invoke
MyIntent
intent
// ...
class | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-10 | intent
// ...
class
MyWidget
extends
StatelessWidget
// ...
@override
Widget
build
BuildContext
context
return
Shortcuts
shortcuts:
LogicalKeySet
Intent
LogicalKeySet
LogicalKeyboardKey
enter
MyIntent
},
child:
Actions
actions:
Type
Action
Intent
>>{
MyIntent:
MyAction
(),
},
child:
Container
(),
); | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-11 | Container
(),
);
Custom Actions and Intents with arguments
To update actions that use intent arguments or hold state,
you need to modify the arguments to the invoke method.
In the example below, the code keeps the value of the
argument in the intent as part of the action instance.
This is because in the old design there is a new instance
of the action created each time it’s executed,
and the resulting action could be kept by the
ActionDispatcher to record the state.
In the example of post migration code below,
the new MyAction returns the state as the result
of calling invoke, since a new instance isn’t created
for each invocation. This state is returned to the caller of
Actions.invoke, or ActionDispatcher.invokeAction,
depending on how the action is invoked.
Code before migration:
class
MyIntent
extends
Intent
const
MyIntent | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-12 | Intent
const
MyIntent
({
this
argument
});
final
int
argument
class
MyAction
extends
Action
MyAction
()
super
key
);
/// The [LocalKey] that uniquely identifies this action to an [Intent].
static
const
LocalKey
key
ValueKey
Type
>(
RequestFocusAction
);
int
state
@override
void
invoke
FocusNode
node
MyIntent | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-13 | FocusNode
node
MyIntent
intent
// ...
state
intent
argument
Code after migration:
class
MyIntent
extends
Intent
const
MyIntent
({
this
argument
});
final
int
argument
class
MyAction
extends
Action
MyIntent
@override
int
invoke
Intent
intent
// ...
return
intent
argument
Timeline | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
9d40044d2529-14 | intent
argument
Timeline
Landed in version: 1.18
In stable release: 1.20
References
API documentation:
Action
ActionDispatcher
Actions
Intent
Shortcuts
Relevant issues:
Issue 53276
Relevant PRs:
Revise Action API
Make Action.enabled be isEnabled(Intent intent) instead | https://docs.flutter.dev/release/breaking-changes/actions-api-revision/index.html |
60539d315078-0 | Adding TextInputClient.currentAutofillScope property
Summary
Context
Description of change
Migration guide
Timeline
References
Summary
A new getter, TextInputClient.currentAutofillScope, was added to the
TextInputClient interface; all TextInputClient subclasses must
provide a concrete implementation of currentAutofillScope.
This getter allows the TextInputClient to trigger an
autofill that involves multiple logically connected input
fields. For example, a “username” field can trigger an
autofill that fills both itself and the “password”
field associated with it.
Context | https://docs.flutter.dev/release/breaking-changes/add-currentAutofillScope-to-TextInputClient/index.html |
60539d315078-1 | Context
On many platforms, autofill services are capable of
autofilling multiple input fields in a single autofill attempt.
For example, username fields and password fields can usually
be autofilled in one go. For this reason, a Flutter input
field that is about to trigger autofill should also provide
the platform with information about other autofillable input
fields logically connected to it.
TextInputClient.currentAutofillScope defines the group of
input fields that are logically connected to this TextInputClient,
and can be autofilled together.
Description of change
TextInputClient now has an additional getter that returns
the AutofillScope that this client belongs to.
This getter is used by the input client to collect autofill
related information from other autofillable input fields
within the same scope.
abstract
class
TextInputClient
AutofillScope
get
currentAutofillScope | https://docs.flutter.dev/release/breaking-changes/add-currentAutofillScope-to-TextInputClient/index.html |
60539d315078-2 | get
currentAutofillScope
If you see the error message “missing concrete implementation of
‘getter TextInputClient.currentAutofillScope’” while compiling
a Flutter app, follow the migration steps listed below.
Migration guide
If you’re not planning to add multifield autofill
support to your TextInputClient subclass,
simply return null in the getter:
class
CustomTextField
implements
TextInputClient
// Not having an AutofillScope does not prevent the input field
// from being autofilled. However, only this input field is
// autofilled when autofill is triggered on it.
AutofillScope
get
currentAutofillScope
null | https://docs.flutter.dev/release/breaking-changes/add-currentAutofillScope-to-TextInputClient/index.html |
60539d315078-3 | get
currentAutofillScope
null
If multifield autofill support is desirable, a common
AutofillScope to use is the AutofillGroup widget.
To get the closest AutofillGroup widget to the text
input, use AutofillGroup.of(context):
class
CustomTextFieldState
extends
State
CustomTextField
implements
TextInputClient
AutofillScope
get
currentAutofillScope
AutofillGroup
of
context
);
For more information, see AutofillGroup.
Timeline
Landed in version: 1.18.0
In stable release: 1.20
References
API documentation:
AutofillGroup | https://docs.flutter.dev/release/breaking-changes/add-currentAutofillScope-to-TextInputClient/index.html |
60539d315078-4 | References
API documentation:
AutofillGroup
TextInputClient.currentAutofillScope
Relevant issues:
Issue 13015: Autofill support
Relevant PRs:
Framework PR that added autofill support | https://docs.flutter.dev/release/breaking-changes/add-currentAutofillScope-to-TextInputClient/index.html |
7baee4d9e216-0 | showAutocorrectionPromptRect method added to TextInputClient
Summary
Context
Description of change
Migration guide
Timeline
References
Summary
A new method,void showAutocorrectionPromptRect(int start, int end),
was added to the TextInputClient interface.
Context
In order to display the iOS autocorrection highlight,
the iOS text input plugin needed a way to inform the
Flutter framework of the highlight’s start and end position.
Description of change
A new method, void showAutocorrectionPromptRect(int start, int end),
was added to the TextInputClient interface. iOS calls this method
when it finds a new potential autocorrect candidate
in the current user input, or when the range of a previously
highlighted candidate changes.
Migration guide | https://docs.flutter.dev/release/breaking-changes/add-showAutocorrectionPromptRect/index.html |
7baee4d9e216-1 | Migration guide
If your application doesn’t implement or subclass TextInputClient,
no migration is needed. If your application doesn’t target iOS,
or the class that implemented the textInputClient interface doesn’t
support autocorrect, you only need to add an empty implementation
for the new method:
class
CustomTextInputClient
implements
TextInputClient
void
showAutocorrectionPromptRect
int
start
int
end
{}
Otherwise, if your app targets iOS and supports autocorrect on iOS,
we recommend that you add a sensible implementation of
void showAutocorrectionPromptRect(int start, int end)
to your TextInputClient subclass.
Code after migration:
// Assume your `TextInputClient` is a `State` subclass, and it has a variable | https://docs.flutter.dev/release/breaking-changes/add-showAutocorrectionPromptRect/index.html |
7baee4d9e216-2 | // `_currentPromptRectRange` that controls the autocorrection highlight.
class
CustomTextInputClient
extends
State
<...>
implements
TextInputClient
@override
void
updateEditingValue
TextEditingValue
value
// When the text changes, the highlight needs to be dismissed.
if
value
text
!=
_value
text
setState
(()
_currentPromptRectRange
null
});
void
_handleFocusChanged
()
// When this text input loses focus, the autocorrection highlight needs | https://docs.flutter.dev/release/breaking-changes/add-showAutocorrectionPromptRect/index.html |
7baee4d9e216-3 | // When this text input loses focus, the autocorrection highlight needs
// to be dismissed.
if
_hasFocus
setState
(()
_currentPromptRectRange
null
});
@override
void
showAutocorrectionPromptRect
int
start
int
end
// Updates the range of the highlight, as iOS requested.
// This method isn't called when iOS decides to
// dismiss the highlight.
setState
(()
_currentPromptRectRange
TextRange
start:
start
end:
end
);
}); | https://docs.flutter.dev/release/breaking-changes/add-showAutocorrectionPromptRect/index.html |
7baee4d9e216-4 | end
);
});
Timeline
In stable release: 1.20
References
API documentation:
TextInputClient
Relevant issues:
Issue 12920
Relevant PRs:
iOS UITextInput autocorrection prompt | https://docs.flutter.dev/release/breaking-changes/add-showAutocorrectionPromptRect/index.html |
5e27931501fc-0 | Android ActivityControlSurface attachToActivity signature change
Summary
Context
Description of change
Migration guide
Timeline
References
Summary
FlutterActivity or
FlutterFragment,
and don’t manually embed a
FlutterView
inside your own custom
A new ActivityControlSurface method:
void
attachToActivity
@NonNull
ExclusiveAppComponent
Activity
exclusiveActivity
@NonNull
Lifecycle
lifecycle
);
is replacing the now deprecated method:
void
attachToActivity
@NonNull
Activity
activity
@NonNull
Lifecycle | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
5e27931501fc-1 | activity
@NonNull
Lifecycle
lifecycle
);
The existing deprecated method with the Activity
parameter was removed in Flutter 2.
Context
In order for custom Activities to also supply the Activity
lifecycle events Flutter plugins expect using the
ActivityAware interface, the FlutterEngine
exposed a getActivityControlSurface() API.
This allows custom Activities to signal to the engine
(with which it has a (0|1):1 relationship) that
it was being attached or detached from the engine.
Note:
This lifecycle signaling is done automatically when you
use the engine’s bundled FlutterActivity
or FlutterFragment, which should be the most
common case. | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
5e27931501fc-2 | However, the previous API had the flaw that it didn’t
enforce exclusion between activities connecting to
the engine, thus enabling n:1 relationships between
the activity and the engine,
causing lifecycle cross-talk issues.
Description of change
After Issue #21272, instead of attaching your activity
to the FlutterEngine by using the:
void
attachToActivity
@NonNull
Activity
activity
@NonNull
Lifecycle
lifecycle
);
API, which is now deprecated, instead use:
void
attachToActivity
@NonNull
ExclusiveAppComponent
Activity
exclusiveActivity
@NonNull
Lifecycle
lifecycle
); | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
5e27931501fc-3 | Lifecycle
lifecycle
);
An ExclusiveAppComponent<Activity> interface
is now expected instead of an Activity.
The ExclusiveAppComponent<Activity> provides a callback
in case your exclusive activity is being replaced by
another activity attaching itself to the FlutterEngine.
The
void
detachFromActivity
();
API remains unchanged and you’re still expected
to call it when your custom
activity is being destroyed naturally.
Migration guide
If you have your own activity holding a
FlutterView, replace calls to:
void
attachToActivity
@NonNull
Activity
activity
@NonNull
Lifecycle
lifecycle
);
with calls to:
void
attachToActivity | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
5e27931501fc-4 | with calls to:
void
attachToActivity
@NonNull
ExclusiveAppComponent
Activity
exclusiveActivity
@NonNull
Lifecycle
lifecycle
);
on the ActivityControlSurface that you obtained by calling
getActivityControlSurface() on the FlutterEngine.
Wrap your activity with an ExclusiveAppComponent<Activity>
and implement the callback method:
void
detachFromFlutterEngine
();
to handle your activity being replaced by another
activity being attached to the FlutterEngine.
Generally, you want to perform the same detaching operations
as performed when the activity is being naturally destroyed.
Timeline
Landed in version: 1.23.0-7.0.pre
In stable release: 2.0.0
References | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
5e27931501fc-5 | References
Motivating bug: Issue #66192—Non exclusive
UI components attached to the FlutterEngine causes
event crosstalk | https://docs.flutter.dev/release/breaking-changes/android-activity-control-surface-attach/index.html |
7405c428c3d9-0 | FlutterMain.setIsRunningInRobolectricTest on Android removed
Summary
Context
Description of change
Migration guide
Timeline
Summary
If you write Java JUnit tests (such as Robolectric tests)
against the Flutter engine’s Java embedding and used the
FlutterMain.setIsRunningInRobolectricTest(true) API,
replace it with the following:
FlutterJNI
mockFlutterJNI
mock
FlutterJNI
class
);
FlutterInjector
setInstance
new
FlutterInjector
Builder
()
setFlutterLoader
new
FlutterLoader
mockFlutterJNI | https://docs.flutter.dev/release/breaking-changes/android-setIsRunningInRobolectricTest-removed/index.html |
7405c428c3d9-1 | new
FlutterLoader
mockFlutterJNI
))
build
());
This should be very uncommon.
Context
The FlutterMain class itself is being deprecated and replaced with the
FlutterInjector class. The FlutterMain class uses a number of
static variables and functions than make it difficult to test.
FlutterMain.setIsRunningInRobolectricTest() is one ad-hoc static
mechanism to allow tests to run on the host machine on JVM without
loading the libflutter.so native library
(which can’t be done on the host machine).
Rather than one-off solutions, all dependency injections needed for tests
in Flutter’s Android/Java engine embedding are now moved to the
FlutterInjector class. | https://docs.flutter.dev/release/breaking-changes/android-setIsRunningInRobolectricTest-removed/index.html |
7405c428c3d9-2 | Within the FlutterInjector class,
the setFlutterLoader() Builder
function allows for control of how the
FlutterLoader class locates and loads
the libflutter.so library.
Description of change
engine commit removed the
commit added a
PR 20473 further refactored
to allow for additional mocking/testing.
Migration guide
Code before migration:
FlutterMain
setIsRunningInRobolectricTest
true
);
Code after migration:
FlutterJNI
mockFlutterJNI
mock
FlutterJNI
class
);
FlutterInjector
setInstance
new
FlutterInjector
Builder
() | https://docs.flutter.dev/release/breaking-changes/android-setIsRunningInRobolectricTest-removed/index.html |
7405c428c3d9-3 | FlutterInjector
Builder
()
setFlutterLoader
new
FlutterLoader
mockFlutterJNI
))
build
());
Timeline
Landed in version: 1.22.0-2.0.pre.133
In stable release: 2.0.0 | https://docs.flutter.dev/release/breaking-changes/android-setIsRunningInRobolectricTest-removed/index.html |
e68f2658847b-0 | Android v1 embedding app and plugin creation deprecation
Summary
Context
Description of change
Migration guide
Timeline
Summary
The flutter create templates for apps and plugins
no longer create Android wrapping based on the
v1 Android embedding as part of our gradual
Android v1 embedding deprecation process described in our
Android Migration Summary.
Application projects using the v1 Android embedding
are encouraged to migrate following the steps described in
Upgrading pre 1.12 Android projects.
Plugins targeting the v1 Android embedding are encouraged
to migrate following the instructions in
Supporting the new Android plugins APIs.
Context
In Flutter version 1.12, we launched a v2 set of
Android APIs based on the io.flutter.embedding
package in order to enable the add-to-app workflow
on Android. | https://docs.flutter.dev/release/breaking-changes/android-v1-embedding-create-deprecation/index.html |
e68f2658847b-1 | Over time, we gradually deprecated the older
v1 Android embeddings based on the
io.flutter.app package.
As of Q2 2020, only 26% of applications used the v1 embeddings.
Since the v2 embeddings were strongly established over
the 7 months since the launch of Flutter v1.12,
we disabled the creation of new app and plugin
projects using the v1 embeddings.
Description of change
The flutter config command no longer has a
togglable enable-android-embedding-v2
flag (which defaulted to true since v1.12).
All projects created with flutter create
and flutter create -t plugin exclusively use the
Android v2 embedding.
Existing v1 applications continue to work.
Existing v1 applications consuming plugins now receive
a warning prompt to migrate to v2 embedding. | https://docs.flutter.dev/release/breaking-changes/android-v1-embedding-create-deprecation/index.html |
e68f2658847b-2 | Existing v1 applications consuming a plugin that targets
only the v2 embedding won’t build and must migrate.
This has been the case since v1.12. However,
the likelihood of encountering this increases as
plugin developers create and publish v2 only plugins.
Existing v2 applications continue to work with or without
plugins.
Existing v2 applications consuming plugins that only
target the v1 embedding continue to receive a warning prompt.
The likelihood of encountering this decreases
as plugin developers create and publish v2 plugins.
Migration guide
For more information,
see Upgrading pre 1.12 Android projects.
Timeline
Landed in version: 1.20.0-8.0
In stable release: 1.22 | https://docs.flutter.dev/release/breaking-changes/android-v1-embedding-create-deprecation/index.html |
a46107333bcf-0 | Replace AnimationSheetBuilder.display with collate
Summary
Context
Description of change
Migration guide
Derive cells per row
Migrate code
Timeline
References
Summary
The AnimationSheetBuilder.display and sheetSize
methods are deprecated, and should be replaced with
AnimationSheetBuilder.collate.
Context | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-1 | Context
AnimationSheetBuilder is a testing utility
class that records frames of an animating widget,
and later composes the frames into a single
animation sheet for golden testing. The old way
of composing involves display to list the images
into a table-like widget, adjusting the testing
surface with sheetSize, and capturing the table
widget for comparison. A new way, collate, has
been added that directly puts the frames together
into an image for comparison, which requires less
boilerplate code and outputs a smaller image without
compromise in quality. APIs for the old way are thus
deprecated.
The reason why collate outputs a smaller image,
is because the old way captures on a testing surface
with pixel ratio 3.0, which means it uses a 3x3 pixel
block of the exactly same color to represent 1 actual
pixel, making the image 9 times as large as necessary
(before PNG compression).
Description of change
The following changes have been made to the
AnimationSheetBuilder class: | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-2 | The following changes have been made to the
AnimationSheetBuilder class:
‘display’ is deprecated and shouldn’t be used
‘sheetSize’ is deprecated and shouldn’t be used
Migration guide
To migrate to the new API, change the process of setting
surface size and displaying the widget into
AnimationSheetBuilder.collate.
Derive cells per row
The collate requires an explicit cellsPerRow
argument, which is the number of frames per
row in the output image. It can be manually counted,
or calculated as follows:
Find the width of frame, specified when constructing
AnimationSheetBuilder. For example, in the following
snippet it’s 80:
final
AnimationSheetBuilder
animationSheet
AnimationSheetBuilder
frameSize:
const
Size
80
30 | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-3 | Size
80
30
));
Find the width of surface size, specified when
setting the surface size; the default is 800.
For example, in the following snippet it’s 600:
tester
binding
setSurfaceSize
animationSheet
sheetSize
600
));
The frames per row should be the result of the two
numbers divided, rounded down. For example,
600 / 80 = 7 (rounded down), therefore
animationSheet
collate
Migrate code
Code before migration:
testWidgets
'Indeterminate CircularProgressIndicator'
WidgetTester
tester
async
final | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-4 | tester
async
final
AnimationSheetBuilder
animationSheet
AnimationSheetBuilder
frameSize:
const
Size
40
40
));
await
tester
pumpFrames
animationSheet
record
const
Directionality
textDirection:
TextDirection
ltr
child:
Padding
padding:
EdgeInsets
all
),
child:
CircularProgressIndicator
(),
),
),
),
const
Duration | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-5 | ),
const
Duration
seconds:
));
// The code starting here needs migration.
tester
binding
setSurfaceSize
animationSheet
sheetSize
());
final
Widget
display
await
animationSheet
display
();
await
tester
pumpWidget
display
);
await
expectLater
find
byWidget
display
),
matchesGoldenFile
'material.circular_progress_indicator.indeterminate.png'
),
); | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-6 | ),
);
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/42767
Code after migration (cellsPerRow is 20, derived from 800 / 40):
testWidgets
'Indeterminate CircularProgressIndicator'
WidgetTester
tester
async
final
AnimationSheetBuilder
animationSheet
AnimationSheetBuilder
frameSize:
const
Size
40
40
));
await
tester
pumpFrames
animationSheet
record
const | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-7 | animationSheet
record
const
Directionality
textDirection:
TextDirection
ltr
child:
Padding
padding:
EdgeInsets
all
),
child:
CircularProgressIndicator
(),
),
),
),
const
Duration
seconds:
));
await
expectLater
animationSheet
collate
20
),
matchesGoldenFile
'material.circular_progress_indicator.indeterminate.png'
),
);
}, | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
a46107333bcf-8 | ),
);
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/42767
It’s expected that related golden test reference images
are invalidated, which should all be updated. The new
images should be identical to the old ones except
1/3 in scale.
Timeline
Landed in version: v2.3.0-13.0.pre
In stable release: 2.5
References
API documentation:
AnimationSheetBuilder
AnimationSheetBuilder.collate
Relevant PRs:
Test WidgetTester handling test pointers | https://docs.flutter.dev/release/breaking-changes/animation-sheet-builder-display/index.html |
b11c9e1bc3d9-0 | AnnotatedRegionLayers return local position relative to clipping region
Summary
Context
Description of change
Migration guide
Timeline
References
Summary
The local position returned by AnnotatedRegionLayers in an
annotation search has been changed to be relative to the clipping
region instead of the layer. This makes the local position more
meaningful and reliable, but breaks code that directly performs
annotation searches and uses the local position.
Context
Annotations are metadata that are assigned during the
rendering phase to regions on the screen.
Searching the annotations with a location gives the
contextual information that contains that location.
They are used to detect mouse events and the theme of app bars. | https://docs.flutter.dev/release/breaking-changes/annotations-return-local-position-relative-to-object/index.html |
b11c9e1bc3d9-1 | When localPosition was first added to the search result,
it was defined as relative to the layer that owned the annotation,
which turned out to be a design mistake.
The offset from the layer is meaningless and unreliable.
For example, a Transform widget draws on the same layer
with an offset if the transform matrix is a simple translation,
or push a dedicated TransformLayer if the matrix is non-trivial.
The former case keeps the previous coordinate origin
(for example, the top left corner of the app),
while the latter case moves the position origin since
it’s on a new layer. The two cases might not produce noticeable
visual differences, since the extra layer might just be a scale of
99%, despite that the annotation search returns different results.
In order to make this local position reliable, we have to choose
one of the results to stick to.
Description of change
The localPosition returned by an AnnotatedRegionLayer
is now the local position it received subtracted by offset,
where offset is the location of the clipping area relative
to the layer. | https://docs.flutter.dev/release/breaking-changes/annotations-return-local-position-relative-to-object/index.html |
b11c9e1bc3d9-2 | class
AnnotatedRegionLayer
extends
ContainerLayer
@override
bool
findAnnotations
>(
AnnotationResult
result
Offset
localPosition
@required
bool
onlyFirst
})
...
if
/* shouldAddAnnotation */
result
add
AnnotationEntry
>(
annotation:
typedValue
// Used to be:
// localPosition: localPosition,
localPosition:
localPosition
offset
));
... | https://docs.flutter.dev/release/breaking-changes/annotations-return-local-position-relative-to-object/index.html |
b11c9e1bc3d9-3 | offset
));
...
Conceptually, this has changed how AnnotatedRegionLayer.offset
and size are defined. They used to mean
“the clipping rectangle that restricts the annotation search”,
while they now jointly represent
“the region of the annotation object”.
Migration guide
Code that is actively using this local position is probably
directly interacting with layers, since using render objects or
widgets have already made this result unreliable. In order to
preserve the previous behavior, you can reimplement
AnnotatedRegionLayer to return a local position without
subtracting the offset.
Timeline
Landed in version: 1.15.2
In stable release: 1.17
References
API documentation:
AnnotatedRegionLayer
AnnotationEntry
Relevant issues:
Issue #49568 | https://docs.flutter.dev/release/breaking-changes/annotations-return-local-position-relative-to-object/index.html |
b11c9e1bc3d9-4 | Relevant issues:
Issue #49568
Relevant PRs:
Make Annotation’s localPosition relative to object | https://docs.flutter.dev/release/breaking-changes/annotations-return-local-position-relative-to-object/index.html |
5f0ef83e7e17-0 | Added BuildContext parameter to TextEditingController.buildTextSpan
Summary
Context
Description of change
Migration guide
Overriding TextEditingController.buildTextSpan
Calling TextEditingController.buildTextSpan
Timeline
References
Summary
A BuildContext parameter was added to TextEditingController.buildTextSpan.
Classes that extend or implement TextEditingController
and override buildTextSpan need to add the BuildContext
parameter to the signature to make it a valid override.
Callers of TextEditingController.buildTextSpan
need to pass a BuildContext to the call.
Context
Any state that is required by buildTextSpan
(other than the TextStyle and withComposing arguments)
needed to be passed into the class that extends
TextEditingController.
Description of change | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-1 | Description of change
With the BuildContext available, users can access
InheritedWidgets inside buildTextSpan
to retrieve state required to style the text,
or otherwise manipulate the created TextSpan.
Consider the example where we have a
HighlightTextEditingController that wants to
highlight text by setting its color to Theme.accentColor.
Before this change the controller implementation would look like this:
class
HighlightTextEditingController
extends
TextEditingController
HighlightTextEditingController
this
highlightColor
);
final
Color
highlightColor
@override
TextSpan
buildTextSpan
({
TextStyle
style
required
bool
withComposing
}) | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-2 | bool
withComposing
})
return
super
buildTextSpan
style:
TextStyle
color:
highlightColor
),
withComposing:
withComposing
);
And users of the controller would need to pass the color
when creating the controller.
With the BuildContext parameter available,
the HighlightTextEditingController can directly access
Theme.accentColor using Theme.of(BuildContext):
class
HighlightTextEditingController
extends
TextEditingController
@override
TextSpan
buildTextSpan
({
required
BuildContext
context
TextStyle
style | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-3 | context
TextStyle
style
required
bool
withComposing
})
final
Color
color
Theme
of
context
accentColor
return
super
buildTextSpan
context:
context
style:
TextStyle
color:
color
),
withComposing:
withComposing
);
Migration guide
Overriding TextEditingController.buildTextSpan
Add a required BuildContext context parameter to the
signature of the buildTextSpan override.
Code before migration:
class | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-4 | Code before migration:
class
MyTextEditingController
@override
TextSpan
buildTextSpan
({
TextStyle
style
required
bool
withComposing
})
/* ... */
Example error message before migration:
Code after migration:
class
MyTextEditingController
@override
TextSpan
buildTextSpan
({
required
BuildContext
context
TextStyle
style
required
bool
withComposing
})
/* ... */
Calling TextEditingController.buildTextSpan | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-5 | /* ... */
Calling TextEditingController.buildTextSpan
Pass a named parameter ‘context’ of type
BuildContext to the call.
Code before migration:
TextEditingController
controller
/* ... */
TextSpan
span
controller
buildTextSpan
withComposing:
false
);
Error message before migration:
Code after migration:
BuildContext
context
/* ... */
TextEditingController
controller
/* ... */
TextSpan
span
controller
buildTextSpan
context:
context
withComposing:
false
); | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
5f0ef83e7e17-6 | withComposing:
false
);
Timeline
Landed in version: 1.26.0
In stable release: 2.0.0
References
API documentation:
TextEditingController.buildTextSpan
Relevant issues:
Issue #72343
Relevant PRs:
Reland “Add BuildContext parameter to TextEditingController.buildTextSpan” #73510
Revert “Add BuildContext parameter to TextEditingController.buildTextSpan” #73503
Add BuildContext parameter to TextEditingController.buildTextSpan #72344 | https://docs.flutter.dev/release/breaking-changes/buildtextspan-buildcontext/index.html |
e8c753927e1e-0 | New Buttons and Button Themes
Summary
Context
API Change: ButtonStyle instead of individual style properties
The styleFrom() ButtonStyle utility methods
ButtonStyle defaults
Migration guide
Restoring the original button visuals
Migrating buttons with custom colors
Migrating buttons with custom foreground and background colors
Migrating buttons with custom overlay colors
Migrating buttons with custom disabled colors
Migrating buttons with custom elevations
Migrating buttons with custom shapes and borders
Timeline
References
Summary
A new set of basic material button widgets and themes have been added
to Flutter. The original classes have been deprecated and will
eventually be removed. The overall goal is to make buttons more
flexible, and easier to configure via constructor parameters or
themes.
Context | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-1 | Context
Rather than try and evolve the existing button classes and their theme
in-place, we have introduced new replacement button widgets and
themes. In addition to freeing us from the backwards compatibility
labyrinthe that evolving the existing classes in-place would entail,
the new names sync Flutter back up with the Material Design spec,
which uses the new names for the button components.
FlatButton
ButtonTheme
TextButton
TextButtonTheme
RaisedButton
ButtonTheme
ElevatedButton
ElevatedButtonTheme
OutlineButton
ButtonTheme
OutlinedButton
OutlinedButtonTheme | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-2 | ButtonTheme
OutlinedButton
OutlinedButtonTheme
The new themes follow the “normalized” pattern that Flutter adopted
for new Material widgets about a year ago. Theme properties and widget
constructor parameters are null by default. Non-null theme properties
and widget parameters specify an override of the component’s default
value. Implementing and documenting default values is the sole
responsibility of the button component widgets. The defaults
themselves are based primarily on the overall Theme’s colorScheme and
textTheme.
Visually, the new buttons look a little different, because they match
the current Material Design spec and because their colors are
configured in terms of the overall Theme’s ColorScheme. There are
other small differences in padding, rounded corner radii, and the
hover/focus/pressed feedback. | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-3 | Many applications will be able to just substitute the new class names
for the old ones. Apps with golden image tests or with buttons whose
appearance has been configured with constructor parameters or with the
original ButtonTheme may need to consult the migration guide and the
introductory material that follows.
API Change: ButtonStyle instead of individual style properties
A button’s ButtonStyle doesn’t define the button’s visual properties,
it defines overrides of the buttons default visual properties,
where the default properties are computed by the button widget
itself. For example, to override a TextButton’s default foreground
(text/icon) color for all states, one could write:
TextButton
style:
ButtonStyle
foregroundColor:
MaterialStateProperty
all
Color
>(
Colors
blue
),
),
onPressed:
() | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-4 | ),
onPressed:
()
},
child:
Text
'TextButton'
),
This kind of override is common; however, in many cases what’s also
needed are overrides for the overlay colors that the text button uses
to indicate its hovered/focus/pressed state. This can be done by
adding the overlayColor property to the ButtonStyle.
TextButton
style:
ButtonStyle
foregroundColor:
MaterialStateProperty
all
Color
>(
Colors
blue
),
overlayColor:
MaterialStateProperty
resolveWith
Color
>(
Set
MaterialState
states | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-5 | Set
MaterialState
states
if
states
contains
MaterialState
hovered
))
return
Colors
blue
withOpacity
0.04
);
if
states
contains
MaterialState
focused
||
states
contains
MaterialState
pressed
))
return
Colors
blue
withOpacity
0.12
);
return
null
// Defer to the widget's default.
},
), | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-6 | },
),
),
onPressed:
()
},
child:
Text
'TextButton'
A color MaterialStateProperty only needs to return a value for the
colors whose default should be overridden. If it returns null, the
widget’s default will be used instead. For example, to just override
the text button’s focus overlay color:
TextButton
style:
ButtonStyle
overlayColor:
MaterialStateProperty
resolveWith
Color
>(
Set
MaterialState
states
if
states
contains
MaterialState
focused
))
return
Colors
red | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-7 | return
Colors
red
return
null
// Defer to the widget's default.
),
),
onPressed:
()
},
child:
Text
'TextButton'
),
The styleFrom() ButtonStyle utility methods
The Material Design spec defines buttons’ foreground and overlay colors in
terms of the color scheme’s primary color. The primary color is
rendered at different opacities, depending on the button’s state. To
simplify creating a button style that includes all of the properties
that depend on color scheme colors, each button class includes a
static styleFrom() method which constructs a ButtonStyle from a simple
set of values, including the ColorScheme colors it depends on. | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-8 | This example creates a button that overrides its foreground color, as
well as its overlay color, using the specified primary color and the
opacities from the Material Design spec.
TextButton
style:
TextButton
styleFrom
primary:
Colors
blue
),
onPressed:
()
},
child:
Text
'TextButton'
),
The TextButton documentation indicates that the foreground color when
the button is disabled is based on the color scheme’s onSurface
color. To override that as well, using styleFrom():
TextButton
style:
TextButton
styleFrom
primary:
Colors
blue
onSurface:
Colors | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-9 | blue
onSurface:
Colors
red
),
onPressed:
null
child:
Text
'TextButton'
),
Using the styleFrom() method is the preferred way to create a
ButtonStyle if you’re trying to create a Material Design
variation. The most flexible approach is defining a ButtonStyle
directly, with MaterialStateProperty values for the states whose
appearance you want to override.
ButtonStyle defaults
Migration guide
Use the following information to migrate your buttons to the
new API.
Restoring the original button visuals
In many cases it’s possible to just switch from the old button class
to the new one. That’s assuming that the small changes in size/shape
and the likely bigger change in colors, aren’t a concern. | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-10 | To preserve the original buttons’ appearance in these cases, one can
define button styles that match the original as closely as you
like. For example, the following style makes a TextButton look
like a default FlatButton:
final
ButtonStyle
flatButtonStyle
TextButton
styleFrom
primary:
Colors
black87
minimumSize:
Size
88
36
),
padding:
EdgeInsets
symmetric
horizontal:
16.0
),
shape:
const
RoundedRectangleBorder
borderRadius:
BorderRadius
all
Radius
circular
2.0 | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-11 | Radius
circular
2.0
)),
),
);
TextButton
style:
flatButtonStyle
onPressed:
()
},
child:
Text
'Looks like a FlatButton'
),
Similarly, to make an ElevatedButton look like a default RaisedButton:
final
ButtonStyle
raisedButtonStyle
ElevatedButton
styleFrom
onPrimary:
Colors
black87
primary:
Colors
grey
300
],
minimumSize:
Size
88 | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
e8c753927e1e-12 | minimumSize:
Size
88
36
),
padding:
EdgeInsets
symmetric
horizontal:
16
),
shape:
const
RoundedRectangleBorder
borderRadius:
BorderRadius
all
Radius
circular
)),
),
);
ElevatedButton
style:
raisedButtonStyle
onPressed:
()
},
child:
Text
'Looks like a RaisedButton'
), | https://docs.flutter.dev/release/breaking-changes/buttons/index.html |
Subsets and Splits