MaterialApp class in Flutter

The MaterialApp class in Flutter is a widget that wraps several essential widgets and is the starting point for many Flutter applications. It provides material design visual structure and functionality, such as themes, routing, and localization. The MaterialApp widget is often used as the root of a Flutter app to set up the basic material design features.

Constructor of MaterialApp class

const MaterialApp(
{Key key,
GlobalKey<NavigatorState> navigatorKey,
Widget home,
Map<String, WidgetBuilder> routes: const <String, WidgetBuilder>{},
String initialRoute,
RouteFactory onGenerateRoute,
InitialRouteListFactory onGenerateInitialRoutes,
RouteFactory onUnknownRoute,
List<NavigatorObserver> navigatorObservers: const <NavigatorObserver>[],
TransitionBuilder builder,
String title: '',
GenerateAppTitle onGenerateTitle,
Color color,
ThemeData theme,
ThemeData darkTheme,
ThemeData highContrastTheme,
ThemeData highContrastDarkTheme,
ThemeMode themeMode: ThemeMode.system,
Locale locale,
Iterable<LocalizationsDelegate> localizationsDelegates,
LocaleListResolutionCallback localeListResolutionCallback,
LocaleResolutionCallback localeResolutionCallback,
Iterable<Locale> supportedLocales: const <Locale>[Locale('en', 'US')],
bool debugShowMaterialGrid: false,
bool showPerformanceOverlay: false,
bool checkerboardRasterCacheImages: false,
bool checkerboardOffscreenLayers: false,
bool showSemanticsDebugger: false,
bool debugShowCheckedModeBanner: true,
Map<LogicalKeySet, Intent> shortcuts,
Map<Type, Action<Intent>> actions}
)

Key Properties of MaterialApp :-

  • home: The default route of the app, usually a Scaffold widget.
  • routes: A map of route names to widget builder functions.
  • initialRoute: The name of the first route to show.
  • initialRoute: The name of the first route to show.
  • onUnknownRoute: A function that returns a route for unknown routes.
  • theme: The theme to use for the app.
  • darkTheme: The dark theme to use for the app.
  • themeMode: The mode to decide whether to use the light or dark theme.
  • locale: The locale for the app.
  • localizationsDelegates: A list of delegates for localization.
  • supportedLocales: A list of supported locales.
  • debugShowCheckedModeBanner: Whether to show the debug banner.