Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Difference between Raw Material Button and Material Button

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

like image 820
Hamza Avatar asked Aug 11 '26 20:08

Hamza


2 Answers

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,
    );
}
like image 125
pr0gramist Avatar answered Aug 13 '26 09:08

pr0gramist


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.

like image 21
GOVIND DIXIT Avatar answered Aug 13 '26 11:08

GOVIND DIXIT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!