Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Material and MaterialApp in Flutter?

Tags:

I am developing an app using Flutter. If I choose MaterialApp as the parent widget of my app, all Text widgets in my app are underlined yellow. On the other hand, if I just use Material as the parent widget, no yellow lines are shown under the Text widgets.

What is the difference between Material and MaterialApp?

like image 236
Developine Avatar asked Jun 27 '18 11:06

Developine


People also ask

What is MaterialApp in Flutter?

MaterialApp Class: MaterialApp is a predefined class in a flutter. It is likely the main or core component of flutter. We can access all the other components and widgets provided by Flutter SDK.

What is difference between material and scaffold?

MaterialApp is the starting point of your app, it tells Flutter that you are going to use Material components and follow material design in your app. Scaffold is used under MaterialApp , it gives you many basic functionalities, like AppBar , BottomNavigationBar , Drawer , FloatingActionButton etc.

What is difference between material app and widget app?

MaterialApp is an extension of the generic top-level widget provided by Flutter: WidgetsApp . WidgetsApp is a convenience widget that abstracts away a number of features required for most mobile apps, such as setting up a navigator and using an app-wide theme.

What is MaterialApp in Dart?

The MaterialApp configures the top-level Navigator to search for routes in the following order: For the / route, the home property, if non-null, is used. Otherwise, the routes table is used, if it has an entry for the route. Otherwise, onGenerateRoute is called, if provided.


1 Answers

MaterialApp is a widget that introduces many interesting tools such as Navigator or Theme to help you develop your app.

Material is, on the other hand, a widget used to define a UI element respecting Material rules. It defines what elevation is, shape, and stuff. Then reused by many material widgets such as Appbar or Card or FloatingButton.

The yellow underlines you can find in Text is introduced by MaterialApp as a fallback Theme. It is here for debug purpose, to warn you that you need to use Material somewhere above your Text.

In short, use both. You should have a MaterialApp near the root of your app. And then use widgets that introduce a Material instance (Such a Scaffold, Appbar, Dialog, ...) when you want to use Text or InkWell.

like image 182
Rémi Rousselet Avatar answered Sep 24 '22 17:09

Rémi Rousselet