Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

FlatButton, RaisedButton and OutlineButton no longer work in Flutter

ErrorFlutter FlatButton is deprecated

Short 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.

  • Applies to Flutter 3.35, Dart 3.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/
  2. 2Match what you see, then jump to its fix

    1. 1The analyzer flags FlatButton, RaisedButton or OutlineButton as deprecated or removedThe old widget class was replacedFix
    2. 2The analyzer rejects the old textColor or color parameters on the new buttonColour parameters moved into ButtonStyleFix
    3. 3The new button is smaller or differently sized than the old oneYou need a set width and heightFix

What does the error look like?

  • Flutter FlatButton is deprecated
  • FlatButton
  • RaisedButton

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 analyze

Confirmed by docs.flutter.dev

Did this fix it?

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 button

2Fix

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 run

Confirmed by docs.flutter.dev

Did this fix it?

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 button

2Fix

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 run

Confirmed by docs.flutter.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.