Scafolding Material App
Scafolding Material App
Marlon L. Castro
MaterialApp
• MaterialApp class - A convenience widget that
wraps a number of widgets that are commonly
required for Material Design applications.
Common MaterialApp Properties
• title: The title property takes in a string as the
object to decide the one-line description of the app
for the device.
• theme: This property takes in ThemeData class as
the object to describe the theme for the
MaterialApp.
• darkTheme: It provided theme data for the dark
theme for the application.
• color: It controls the primary color used in the
Common MaterialApp Properties
• debugShowCheckedModeBanner: This
property takes in a boolean as the object to
decide whether to show the debug banner or
not.
• home: This property takes in widget as the
object to show on the default route of the app.
Simple Material App Example:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'GeeksforGeeks’,
theme: ThemeData(primarySwatch: Colors.green),
darkTheme: ThemeData(primarySwatch: Colors.grey),
color: Colors.amberAccent,
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('GeeksforGeeks')),
),
);
}
}
Output
Scaffold
• Scaffold is a class in flutter which provides many
widgets or we can say APIs like Drawer, Snack-Bar,
Bottom-Navigation-Bar, Floating-Action-Button, App-
Bar, etc. Scaffold will expand or occupy the whole
device screen. It will occupy the available space.
Scaffold will provide a framework to implement the
basic material design layout of the application.
Properties of Scaffold Class:
• appBar: It displays a horizontal bar which mainly placed at the top of
the Scaffold. appBar uses the widget AppBar which has its own
properties like elevation, title, brightness, etc.
void main() {
runApp(gfgApp()); //MaterialApp
}
MaterialApp gfgApp() {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('GeeksforGeeks'),
), //AppBar
body: const Center(
child: Text(
'GeeksforGeeks',
style: TextStyle(fontSize: 24),
), //Text
), // center
), //Scaffold
debugShowCheckedModeBanner: false, //Removing Debug Banner
);
}
Center Widget
• Center widget comes built-in with flutter, it aligns its
child widget to the center of the available space on
the screen. The size of this widget will be as big as
possible if the widthFactor and heightFactor
properties are set to null and the dimensions are
constrained. And in case the dimensions are not
constrained and the widthFactor and HeightFactor
are set to null then the Center widget takes the size
of its child widget.
Syntax
Syntax:
Center({Key key,
double widthFactor,
double heightFactor,
Widget child})
Properties of Center Widget:
• widthFactor: This property takes a double value as a
parameter and it sets the Center widget’s width as the same
as the child’s width multiplied by this factor. For example, if it
is set to 3.0 then the Center widget will take three times the
size of its child widget.
• heightFactor: This property also takes in a double value as a
parameter and it sets the Center widget’s height as the same
as the child’s height multiplied by this factor.
• child: This property takes in a widget as a parameter to be
displayed inside the Center widget on the screen.
• alignment: This property takes in AlignmentGeometry as the
parameter value to determine how the child widget will be
aligned with respect to the Center widget.
Example
body: Center(
// heightFactor: 3,
// widthFactor: 0.8,
child: Container(
color: Colors.green,
child: Text(
'Center Widget',
textScaleFactor: 3,
style: TextStyle(color: Colors.white),
),
),
),
Flutter Images
• When you create an app in Flutter, it includes both code and
assets (resources). An asset is a file, which is bundled and
deployed with the app and is accessible at runtime. The asset
can include static data, configuration files, icons, and images.
The Flutter supports many image formats, such as JPEG, WebP,
PNG, GIF, animated WebP/GIF, BMP, and WBMP.