The `IconData` class is now marked as `final`, which prevents it from being implemented or extended. This change is part of an effort to generalize the mechanism for tree-shaking assets and native code.
- Who is affected
- Applications and packages relying on the previous behaviour or signature. Code that uses IconData.
- Practical impact
- Behaviour or API differences that can break builds or change runtime behaviour.
- What action should I take?
- Follow the official migration guide below, update affected call sites, run `dart fix --apply` where a fix is available, then run your tests.
Before and after (from the official guide)
| 1 | − | enum AppIcons implements IconData { |
| 2 | − | arrowUpward(0xe062), |
| 3 | − | arrowDownward(0xe061); |
| 4 | ||
| 5 | − | const AppIcons(this.codePoint) |
| 6 | − | : fontFamily = 'MaterialIcons', |
| 7 | − | fontPackage = null, |
| 8 | − | matchTextDirection = false; |
| 9 | ||
| 10 | @override | |
| 11 | − | final int codePoint; |
| 12 | − | @override |
| 13 | − | final String? fontFamily; |
| 14 | − | @override |
| 15 | − | final String? fontPackage; |
| 16 | − | @override |
| 17 | − | final bool matchTextDirection; |
| 18 | } | |
| 19 | ||
| 20 | Widget build(BuildContext context) { | |
| 21 | − | // Example usage of AppIcons: |
| 22 | − | return Icon(AppIcons.arrowUpward); |
| 23 | } |
| 1 | + | final class AppIconData { |
| 2 | + | final IconData iconData; |
| 3 | ||
| 4 | + | const AppIconData._(this.iconData); |
| 5 | ||
| 6 | + | static const arrowUpward = AppIconData._( |
| 7 | + | IconData(0xe062, fontFamily: 'MaterialIcons'), |
| 8 | + | ); |
| 9 | + | static const arrowDownward = AppIconData._( |
| 10 | + | IconData(0xe061, fontFamily: 'MaterialIcons'), |
| 11 | + | ); |
| 12 | + | |
| 13 | + | static const values = [arrowUpward, arrowDownward]; |
| 14 | + | } |
| 15 | + | |
| 16 | + | class AppIcon extends StatelessWidget { |
| 17 | + | const AppIcon(this.icon, {super.key}); |
| 18 | + | final AppIconData icon; |
| 19 | + | |
| 20 | @override | |
| 21 | + | Widget build(BuildContext context) { |
| 22 | + | return Icon(icon.iconData); |
| 23 | + | } |
| 24 | } | |
| 25 | ||
| 26 | Widget build(BuildContext context) { | |
| 27 | + | // Usage preserves dot shorthand if the type can be inferred: |
| 28 | + | return const AppIcon(AppIconData.arrowUpward); |
| 29 | + | // Or if inferred: const AppIcon(.arrowUpward) |
| 30 | } |
Raw before / after
enum AppIcons implements IconData {
arrowUpward(0xe062),
arrowDownward(0xe061);
const AppIcons(this.codePoint)
: fontFamily = 'MaterialIcons',
fontPackage = null,
matchTextDirection = false;
@override
final int codePoint;
@override
final String? fontFamily;
@override
final String? fontPackage;
@override
final bool matchTextDirection;
}
Widget build(BuildContext context) {
// Example usage of AppIcons:
return Icon(AppIcons.arrowUpward);
}final class AppIconData {
final IconData iconData;
const AppIconData._(this.iconData);
static const arrowUpward = AppIconData._(
IconData(0xe062, fontFamily: 'MaterialIcons'),
);
static const arrowDownward = AppIconData._(
IconData(0xe061, fontFamily: 'MaterialIcons'),
);
static const values = [arrowUpward, arrowDownward];
}
class AppIcon extends StatelessWidget {
const AppIcon(this.icon, {super.key});
final AppIconData icon;
@override
Widget build(BuildContext context) {
return Icon(icon.iconData);
}
}
Widget build(BuildContext context) {
// Usage preserves dot shorthand if the type can be inferred:
return const AppIcon(AppIconData.arrowUpward);
// Or if inferred: const AppIcon(.arrowUpward)
}Official migration guide (excerpt, © The Flutter Authors, CC BY 3.0)
Instead of implementing IconData,
such as with an enum that supports dot shorthand,
type safety, and an automated .values list,
use a wrapper class with static const instances.
Migrating custom icon types
If you used an enum that implements IconData,
migrate to a class with static const instances and a custom widget.
Code before migration:
enum AppIcons implements IconData {
arrowUpward(0xe062),
arrowDownward(0xe061);
const AppIcons(this.codePoint)
: fontFamily = 'MaterialIcons',
fontPackage = null,
matchTextDirection = false;
@override
final int codePoint;
@override
final String? fontFamily;
@override
final String? fontPackage;
@override
final bool matchTextDirection;
}
Widget build(BuildContext context) {
// Example usage of AppIcons:
return Icon(AppIcons.arrowUpward);
}To maintain dot shorthand support and type safety, use a wrapper class and a custom widget.
Code after migration:
final class AppIconData {
final IconData iconData;
const AppIconData._(this.iconData);
static const arrowUpward = AppIconData._(
IconData(0xe062, fontFamily: 'MaterialIcons'),
);
static const arrowDownward = AppIconData._(
IconData(0xe061, fontFamily: 'MaterialIcons'),
);
static const values = [arrowUpward, arrowDownward];
}
class AppIcon extends StatelessWidget {
const AppIcon(this.icon, {super.key});
final AppIconData icon;
@override
Widget build(BuildContext context) {
return Icon(icon.iconData);
}
}
Widget build(BuildContext context) {
// Usage preserves dot shorthand if the type can be inferred:
return const AppIcon(AppIconData.arrowUpward);
// Or if inferred: const AppIcon(.arrowUpward)
}If you rely on .values for tools like Widgetbook,
you can maintain the values list manually as shown in
the previous example or use code generation.
Ignore the mustBeConst lint
To enable tree-shaking, some IconData parameters are
marked with the mustBeConst annotation.
If you must use a non-const IconData and
are willing to forgo tree-shaking for that icon,
add an ignore comment for the lint.
// ignore: non_const_argument_for_const_parameter
Icon(myDynamicIconData);AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.Listed in the official breaking-changes index (docs.flutter.dev/release/breaking-changes).
An official announcement or migration guide documents an intended behaviour or API change. A verified source change (git diff) shows code changed but does not by itself prove a public API is breaking. AI interpretations are labelled and never used to classify a change.
- Official migration guide
- Mark IconData final and @mustBeConst
- Breaking Change: Marking class IconData as final
- Marking IconData's constructor parameters as @mustBeConst
- Source commit
- b3045439b7c0
- Source last updated
- Oct 21, 2026
- Last synchronized
- Oct 21, 2026
- Publication status
- published
Publication history
- Oct 21, 2026, 8:31 PM: new → published (ingestion) — Backed by an official breaking-change/migration guide.
AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.