Professional Documents
Culture Documents
Unit 3 Mad - 1
Unit 3 Mad - 1
READING
MATERAIL
6TH SEMESTER
SUMMER-2024
BHAGWAN MAHAVIR UNIVERSITY
BHAGWAN MAHAVIR POLYTECHNIC
IT DEPARTMENT
READING MATERIAL
Fig – Widget
In Flutter, widgets can be grouped into multiple categories based on their features, as listed
below −
• Scaffold
• AppBar
• BottomNavigationBar
• TabBar
• TabBarView
• ListTile
• FloatingActionButton
• FlatButton
• IconButton
• TextField
• Checkbox
• Radio
• Slider
• Date & Time Pickers
• SimpleDialog
• AlertDialog
Layout widgets
To compose multiple widgets into a single widget, Flutter provides large number of widgets
with layout feature.
Some of the popular layout widgets are as follows −
• Container − A rectangular box decorated using BoxDecoration widgets with
background, border and shadow.
• Center − Center its child widget.
Visible widget
The visible widgets are related to the user input and output data. Some of the important types
of this widget are:
• Text
• Button
• Image
• Icon
Invisible widget
The invisible widgets are related to the layout and control of widgets. It provides controlling
how the widgets actually behave and how they will look onto the screen. Some of the important
types of these widgets are:
• Column
• Row
• Center
• Padding
• Scaffold
• Stack
o StatelessWidget
o StatefulWidget
StatefulWidget
A StatefulWidget has state information. It contains mainly two classes: the state object and
the widget. It is dynamic because it can change the inner data during the widget lifetime. This
widget does not have a build() method. It has createState() method, which returns a class that
extends the Flutters State Class. The examples of the StatefulWidget are Checkbox, Radio,
Slider, InkWell, Form, and TextField.
Example:
The Stateless Widget does not have any state information. It remains static throughout its
lifecycle. The examples of the Stateless Widget are Text, Row, Column, Container, etc.
Example
Property Descriptions
darkTheme It provided theme data for the dark theme for the
application.
import 'package:flutter/material.dart';
void main() {
runApp(const GFGapp());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello',
theme: ThemeData(primarySwatch: Colors.green),
darkTheme: ThemeData(primarySwatch: Colors.grey),
color: Colors.amberAccent,
supportedLocales: {const Locale('en', ' ')},
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Helloworld')),
),
);
}
}
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.
Property Descriptions
Example of floatingActionButton
onPressed: () {
// action on button press
},
),
);
}
Example of drawer
drawer: Drawer(
child: ListView(
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.green,
),
child: Text(
'Drawer Example',
style: TextStyle(
color: Colors.green,
fontSize: 24,
),
),
),
ListTile(
title: Text('Item 1'),
),
ListTile(
title: Text('Item 2'),
),
],
),
),
Example of bottomNavigationBar:
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0,
fixedColor: Colors.green,
items: const [
BottomNavigationBarItem(
label: "Home",
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
label: "Search",
icon: Icon(Icons.search),
),
BottomNavigationBarItem(
label: "Profile",
icon: Icon(Icons.account_circle),
),
],
onTap: (int indexOfItem) {}),
Property Descriptions
backgroundColor This property is used to add colors to the background of the Appbar.
elevation This property is used to set the z-coordinate at which to place this app
bar relative to its parent.
shape This property is used to give shape to the Appbar and manage its
shadow.
Example:
{
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Hello'),
), //AppBar
body: const Center(
child: Text(
'Hello World',
style: TextStyle(fontSize: 24),
), //Text
), // center
), //Scaffold
debugShowCheckedModeBanner: false, //Removing Debug Banner
);
}
Step 1: First, we need to create a new folder inside the root of the Flutter project and named it
assets. We can also give it any other name if you want.
Step 3: Update the pubspec.yaml file. Suppose the image name is tablet.png, then
pubspec.yaml file is:
assets:
- assets/tablet.png
- assets/background.png
If the assets folder contains more than one image, we can include it by specifying the directory
name with the slash (/) character at the end.
flutter:
assets:
- assets/
Step 4: Finally, open themain.dart file and insert the following code.
import 'package:flutter/material.dart';
}
}
Flutter icons widget has different properties for customizing the icons. These properties are
explained below:
Property Descriptions
icon It is used to specify the icon name to display in the application. Generally,
Flutter uses material design icons that are symbols for common actions and
items.
size It is used to specify the size of the icon in pixels. Usually, icons have equal
height and width.
Fig: Container
Properties Description
height and width By default, a container class takes the space that is
required by the child. We can also specify the height
and width of the container based on our requirements.
Property Descriptions
clipBehaviour This property holds Clip class as the object to decide whether the
content on the Row or Column should be clipped or not.
direction This property holds as the Axis enum object to decide the direction
used in the main axis. For Row and Column, it is fixed.
runtimeType This property tells the run-time type of the Row or Column widget.
Row Column
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Container(
width: 50,
height: 100,
color: Colors.deepOrange,
),
Container(
width: 50,
height: 100,
color: Colors.tealAccent,
),
Container(
width: 50,
height: 100,
color: Colors.teal,
),
Container(
width: 50,
height: 100,
color: Colors.amber,
),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Container(
width: 50,
height: 100,
color: Colors.deepOrange,
),
Container(
width: 50,
height: 100,
color: Colors.tealAccent,
),
Container(
width: 50,
height: 100,
color: Colors.teal,
),
Container(
width: 50,
height: 100,
color: Colors.amber,
),
],
),
Property Descriptions
flaxFactor Flex factor is the ratio in which available space is divided among the children
to occupy the main axis. If the flex factor is zero or NULL the child will
allocate its size on its own.
child: Container(
color: Colors.green,
padding: const EdgeInsets.all(14),
child: Image.asset('image/dicel.png'),
),
onPressed: () {},
),
), //Expanded
], //<Widget>
), //Row
); //center
}
Parameters
Property Descriptions
onLongPress the action to be executed when the button is long pressed by the user
Styling a Button
The styling of an elevated button is quite different from the rest of the buttons. You have to
use ButtonStyle as a style parameter. After that, pass ElevatedButtonThemeData is
passed as button theme to ThemeData. Styling for elevated button is done
using ElevatedButton.styleFrom. Specific styling for a button explicitly is done
using ButtonStyle parameter as given below:
ElevatedButton(
child: Text('Elevated Button'),
style: ElevatedButton.styleFrom(
primary: Colors.green,
),
onPressed: () {},
),
Property Descriptions
activeColor This property takes the Color class as the object to fill in the ChechBox when
it is checked.
autofocus This property takes in a boolean value as the object. If it is set to true
the CheckBox gets selected at the initial focus.
checkColor This property also takes in Color class as the object. It assigns color to the
check icon.
focusColor This property also takes in Color class as the object to give color to the
checkbox when it is in focus.
focusNode It sets an additional focus node to get the focus of the cursor. It takes
in FocusNode as the object.
hoverColor The hoverColor property takes in Color class as the object. It controls the
color of the checkbox at the time of hover.
value This property takes in a boolean value as the object to determine whether
the CheckBox is checked or not.
groupValue: It is used to specify the currently selected item for the radio button group.
onChanged: It will be called whenever the user selects the radio button.
Property Descriptions
child The child property takes in a widget as the object to show below
the Theme widget in the widget tree.
data This property takes in ThemeData class as the object to specify the
styling, colors and typography to be used.
// font
fontFamily: 'Georgia',
//text style
textTheme: TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyText2: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
)
);
In simple words, SafeArea is basically a padding widget, which adds any necessary padding
to your app, based on the device it is running on. If your app’s widgets are overlaying any of
the system’s features like notches, status bar, camera holes, or any other such features,
then SafeArea would add padding around the app, as required.
Internally SafeArea uses MediaQuery to check the dimensions of the display screen and
includes extra padding if needed.
Property Descriptions
Property Descriptions
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Container(
height: 175,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.red,
), //BoxDecoration
), //Container
), //Flexible
StatelessWdget StatefulWidget
Stateless Widgets are static widgets. Stateful Widgets are dynamic widgets.
They do not depend on any data change They can be updated during runtime
or any behavior change. based on user action or data change.
Stateless Widgets do not have a state, Stateful Widgets have an internal state
they will be rendered once and will not and can re-render if the input data
update themselves, but will only be changes or if Widget’s state changes.
updated when external data changes.