MaterialApp
MaterialApp
MaterialApp is a pre-built widget in Flutter that provides a basic structure for creating Material Design-styled applications. It provides a number of pre-built widgets that conform to the Material Design guidelines, such as buttons, text fields, and navigation drawers.
Here is an example of how we can use MaterialApp:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My First Flutter App'),
),
body: Center(
child: Text('Hello World!'),
),
),
));
}
In this example, we create a new MaterialApp widget and pass it a Scaffold widget as its home. The Scaffold widget provides a basic structure for our application, including an app bar and a center-aligned body that displays the text "Hello World!".
Attributes
Some common attributes of MaterialApp include:
title: The title of the app, which is displayed in the app bar.
home: The widget that is displayed as the home screen of the app.
routes: A map of named routes that can be used to navigate to different screens within the app.
theme: AThemeDataobject that defines the overall theme of the app, including colors, fonts, and other visual elements.
debugShowCheckedModeBanner: A boolean value that determines whether a banner is displayed in debug mode, indicating that the app is running in debug mode.
These are just a few examples of the many attributes that can be set on a MaterialApp widget in Flutter.