Skip to main content

Flutter: Use the Material App widget

import 'package:flutter/material.dart';

void main() => runApp(
    MyApp()
);

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Home')
        ),
        body: Text('Body'),
        ),
      );
  }
}

The function runApp requires you pass it an object of type Widget to render the screen.

The MaterialApp class provides a widget with some built in functionality. If we look at the constructor of MaterialApp what named parameters we can pass. 

  • home takes a Widget
  • routes take a map of Strings and Widgets
  • title takes a strong.

Scaffold creates a visual scaffold for material design widgets. It provides a framework of common elements found in mobile applications like AppBarBottomAppBarFloatingActionButtonBottomSheetDrawerSnackbar.