Flutter: Difference between Raw Material Button and Material Button

1,690

Solution 1

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,
    );
}

Solution 2

From official Flutter Docs

MaterialButton class

A utility class for building Material buttons that depend on the ambient 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. To have an enabled button, make sure to pass a non-null value for onPressed.

RawMaterialButton class

This class does not use the current Theme or ButtonTheme 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.

Solution 3

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.

Share:
1,690
Hamza
Author by

Hamza

I'm a Computer Sciences student in 5th Semester right now. I'm into Flutter Development for about 7-8 Months now. I'm really interested to learn: Machine Learning (TensorFlow specially) Augmented Reality (AR Core API) Other tech like, data mining, deep learning, data warehousing etc. In addition to this, I'm also a video editor and love gaming too. You can find me at different platforms as well.

Updated on December 16, 2022

Comments

  • Hamza
    Hamza over 1 year

    Hello There Everyone! How's your day going? I hope its brilliant <3

    I need a little bit of your help here, I've been using Raw Material Button and Material button lot in my code, But I don't know what is the difference between Raw Material button and Material Button?.

    Because they look similar while using them.

    Thanks in Advance <3

  • Hamza
    Hamza over 4 years
    Sir Thanks You So very much, really helpful especially with Code <3
  • Hamza
    Hamza over 4 years
    Thanks a lot, It helped really :) :)
  • Hamza
    Hamza over 4 years
    Thank You So very much. I'll look into the doc details if necessary.