Flutter: Difference between Raw Material Button and Material Button
Solution 1
From docs attached to the classes:
MaterialButton
is utility class for building Material buttons that depend on the ambientButtonTheme
andTheme
.
and
RawMaterialButton
does not use the currentTheme
orButtonTheme
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, RawMaterialButton
s 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.
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, 2022Comments
-
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 over 4 yearsSir Thanks You So very much, really helpful especially with Code <3
-
Hamza over 4 yearsThanks a lot, It helped really :) :)
-
Hamza over 4 yearsThank You So very much. I'll look into the doc details if necessary.