Flutter: Difference between Raw Material Button and Material Button Flutter: Difference between Raw Material Button and Material Button dart dart

Flutter: Difference between Raw Material Button and Material Button


From docs attached to the classes:

MaterialButton is utility class for building Material buttons that depend on the ambient ButtonTheme and Theme.

and

RawMaterialButton does not use the current Theme or ButtonTheme to compute default values for unspecified parameters.

And that's really it - the difference is in the default values. Under the hood MaterialButton is using RawMaterialButton

Widget build(BuildContext context) {    final ThemeData theme = Theme.of(context);    final ButtonThemeData buttonTheme = ButtonTheme.of(context);    return RawMaterialButton(      onPressed: onPressed,      onHighlightChanged: onHighlightChanged,      // so many properties here...      child: child,      materialTapTargetSize: materialTapTargetSize ?? theme.materialTapTargetSize,    );}


From official Flutter Docs

MaterialButton class

A utility class for building Material buttons that depend on theambient ButtonTheme and Theme.

The button's size will expand to fit the child widget, if necessary.

MaterialButtons whose onPressed handler is null will be disabled. Tohave an enabled button, make sure to pass a non-null value foronPressed.

RawMaterialButton class

This class does not use the current Theme or ButtonTheme to computedefault values for unspecified parameters.

It's intended to be usedfor custom Material buttons that optionally incorporate defaults fromthe themes or from app-specific sources.


MaterialButton class is used for building buttons that depend on ambient ButtonTheme and Theme. On the other hand, RawMaterialButtons does not use ButtonTheme or Theme. According to documentation,

RawMaterialButton does not use ButtonTheme or Theme to compute default values for unspecified parameters. It's intended to be used for custom Material buttons that optionally incorporate defaults from the themes or from app-specific sources.

Refer the documentation for more details here.