US Office

1176 Shadeville Rd, Crawfordville Florida 32327, USA

 +1 (850) 780-1313

India Office

Office No 405, Kabir Shilp, Opp. Kansar Hotel, Opp. Landmark, Kudasan, Gandhinagar, Gujarat 382421

[email protected]

What is MaterialApp class in Flutter?

What is MaterialApp class in Flutter?

What is MaterialApp class in Flutter?

MaterialApp is a predefined class in a flutter. So, it is likely the main or core component of flutter. So, in this article, we will see what is MaterialApp class in Flutter.

What is MaterialApp class in Flutter?

We can access all the other components and widgets provided by Flutter SDK. To clarify, Text widget, AppBar widget, Scaffold widget, ListView widget, StatelessWidget,  StatefulWidget, etc. are the widgets that can be accessed. There are also many more widgets that are accessed using MaterialApp class. Using this widget, we can make an attractive app.

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: 'GeeksforGeeks',
    theme: ThemeData(
      primarySwatch: Colors.green
    ),
    home: Scaffold(
      appBar: AppBar(
        title:Text(
          'GeeksforGeeks'
        )
      ),
    ),
  ));
}

Explanation of code:

  • import statement: The import statement is used to import the libraries provided by the flutter SDK. So, here we have imported the ‘material.dart’ file.
  • main() function: We also have a main function in which we have to write the statements that are to be executed. The return type of the main function is ‘void’.
  • runApp (Widget widget) function: The void runApp takes a widget as an argument and sets it on a screen. It also gives the constraints to the widget to fit into the screen. It makes the given widget the root widget of the app and other widgets as the child of it.
  • title: This property is used to provide a short description of the application. So, when the user presses the recent apps button on mobile the text in the title is displayed.
  • theme: This property is used to provide the default theme to the application. So, we use the inbuilt class/widget named ThemeData(). Also in Themedata() widget, we have to write the different properties related to the theme. Here we have used the primarySwatch. It is used to define the default themecolor of the application. So to choose the color we have used the Colors class from the material library.
  • home: It is used for the default route of the app. It means the widget defined in it is displayed when the application starts normally. So, here we have defined the Scaffold widget inside the home property.

Conclusion:

Thanks for being with us on a Flutter Journey!

So, in this article, we have seen what is MaterialApp class in Flutter. Also, feel free to comment and provide any other suggestions regarding Flutter tips & tricks.

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology. Daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Post a Comment