Module 1
Module 1
Introduction to Flutter
Intended Learning Outcomes
At the end of the lesson, you should be able to:
1. Learn the basics of Flutter framework.
2. Install Flutter SDK and set up Android Studio to develop Flutter
based application,
3. Understand the architecture of Flutter framework
4. Develop a simple mobile application using Flutter framework.
What is Flutter?
• Flutter is an open source framework to create high quality, high
performance mobile applications across mobile operating systems -
Android and iOS.
• It provides a simple, powerful, efficient and easy to understand SDK
to write mobile application in Google’s own language, Dart.
Introduction
• There are many frameworks available to develop a mobile application.
Android provides a native framework based on Java language and iOS
provides a native framework based on Objective-C / Swift language.
• To develop an application supporting both the OSs, we need to code in two
different languages using two different frameworks. To help overcome this
complexity, there exists mobile frameworks supporting both OS.
• Flutter – a simple and high performance framework based on Dart
language, provides high performance by rendering the UI directly in the
operating system’s canvas rather than through native framework.
• Flutter also offers many ready to use widgets (UI) to create a modern
application. These widgets are optimized for mobile environment and
designing the application using widgets is as simple as designing HTML.
Setting Up for Flutter
Development
Flutter Installation in Windows
In this section, let us see how to install Flutter SDK and its requirement in a
windows system.
Step 1 − Go to URL, https://docs.flutter.dev/get-started/install/windows and
download the latest Flutter SDK. As of Jan 2022, the version is 2.8.1 and the
file is flutter_windows_v2.8.1-stable.zip.
Step 2 − Unzip the zip archive in a folder, say C:\flutter\
Step 3 − Update the system path to include flutter bin directory.
Step 4 − Flutter provides a tool, flutter doctor to check that all the
requirement of flutter development is met.
flutter doctor
Step 3 − Update the system path to include flutter bin directory
Click Search icon > Type edit the system environment> Click Environment Variables
In User variables for User > Click Path > Edit
Click New > Copy/paste the path of the flutter bin folder
Installation in Windows
Step 5 − Running the above command will analyze the system and
show its report as shown below
Installation in Windows
Step 6 − Install the latest Android SDK, if reported by flutter doctor
Step 7 − Install the latest Android Studio, if reported by flutter doctor. Download:
https://developer.android.com/studio
Step 8 − Start an android emulator or connect a real android device to the system.
Step 9 − Install Flutter and Dart plugin for Android Studio. It provides startup
template to create new Flutter application, an option to run and debug Flutter
application in the Android studio itself, etc.,
Open Android Studio.
Click File → Settings → Plugins.
Select the Flutter plugin and click Install.
Click Yes when prompted to install the Dart plugin.
Restart Android studio.
YouTube Video
• If you’re stuck, watch this video:
• https://www.youtube.com/watch?v=6VxMWJV8Mm4
The Anatomy of a Flutter App
Create an Android Virtual Device (AVD)
Click Phone > Choose your
Click Create Device preferred Phone e.g Nexus 6P
Click Next
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Demo App'),
),
body: Center(
child:
Text(
'Hello World',
)
),
)
);
}
}
Let us understand the dart code line by line.
• Line 1 − imports the flutter package, material. The material is a
flutter package to create user interface according to the Material
design guidelines specified by Android.
• Line 3-5 − This is the entry point of the Flutter application.
Calls runApp function and pass it an object of MyApp class. The
purpose of the runApp function is to attach the given widget to the
screen.
• Line 6-11 − Widget is used to create UI in flutter
framework. StatelessWidget is a widget, which does not maintain
any state of the widget.
• MyApp extends StatelessWidget and overrides its build method.
The purpose of the build method is to create a part of the UI of
the application.
• Here, build method uses MaterialApp, a widget to create the root
level UI of the application.
• It has three properties - title, theme and home.
• Line 12 − MyApp returns Scaffold Widget.