FlatButton, RaisedButton and OutlineButton no longer work in Flutter
Flutter FlatButton is deprecatedShort answer
FlatButton, RaisedButton and OutlineButton were replaced by TextButton, ElevatedButton and OutlinedButton. Colours, shape and size now go into one ButtonStyle, usually built with styleFrom. Use foregroundColor and backgroundColor for colours, and minimumSize or fixedSize for width and height.
Fix it fast
1Find out which cause you have
List every old button in your code, so you know how many places need the change.
grep -rn "FlatButton\|RaisedButton\|OutlineButton" lib/2Match what you see, then jump to its fix
- 1
The analyzer flags FlatButton, RaisedButton or OutlineButton as deprecated or removedThe old widget class was replacedFix - 2
The analyzer rejects the old textColor or color parameters on the new buttonColour parameters moved into ButtonStyleFix - 3
The new button is smaller or differently sized than the old oneYou need a set width and heightFix
- 1
What does the error look like?
Flutter FlatButton is deprecatedFlatButtonRaisedButton
Cause 1 of 3
The old widget class was replaced
1Check
The three old classes map one to one to new ones: FlatButton to TextButton, RaisedButton to ElevatedButton, OutlineButton to OutlinedButton.
grep -rn "FlatButton(" lib/2Fix
Rename the widget. The onPressed and child parameters stay the same.
TextButton(
onPressed: () {},
child: const Text('Save'),
)3Verify
The analyzer no longer reports the class.
flutter analyzeConfirmed by docs.flutter.dev
Cause 2 of 3
Colour parameters moved into ButtonStyle
1Check
The new buttons are not configured with many constructor parameters. A single style object holds them.
grep -rn "textColor:\|color:" lib/ | grep -i button2Fix
Use styleFrom. The old textColor becomes foregroundColor, and the old RaisedButton color becomes backgroundColor.
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
onPressed: () {},
child: const Text('Delete'),
)3Verify
Run the app. The button shows the same colours as before.
flutter runConfirmed by docs.flutter.dev
Cause 3 of 3
You need a set width and height
1Check
The new buttons size themselves from their style. The width and height are not constructor parameters.
grep -rn "ButtonTheme\|minWidth\|height:" lib/ | grep -i button2Fix
Set fixedSize in the style for an exact size, or minimumSize for a lower limit. You can also wrap the button in a SizedBox.
ElevatedButton(
style: ElevatedButton.styleFrom(
fixedSize: const Size(120, 48),
),
onPressed: () {},
child: const Text('Fixed'),
)3Verify
Run the app and check the button against the design.
flutter runConfirmed by docs.flutter.dev
How do I stop it coming back?
- Set the look of all buttons once, in the theme (textButtonTheme, elevatedButtonTheme, outlinedButtonTheme).
- Run flutter analyze in CI so deprecations show up before they become removals.
- Read the migration guide of a Flutter upgrade before the upgrade, not after.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix