Mobile App Development with Flutter Guide
Mobile App Development with Flutter Guide
Development MADT-4118
Instructor
Dr. Tanzila Kehkashan
UOL-Sgd
1
Module 1: Introduction to Mobile Application Development...............................................................3
[Link] & Evaluation Criteria......................................................................................3
[Link] is Flutter?..........................................................................................................................3
Key Concept: Cross-Platform Development.....................................................................3
Why is Cross-Platform Development Important?...........................................................3
1.1Understanding Key Terms................................................................................................4
1.2How is Flutter Different from Other Cross-Platform Tools?........................................5
Advantages of Flutter’s Rendering............................................................................................5
1.4Benefits of Flutter......................................................................................................................6
1.4.1................................................................................ Faster Time to Market
................................................................................................................................................6
1.4.2............................................................................................ Cost Efficiency
................................................................................................................................................6
1.4.3....................................................................................... High Performance
...............................................................................................................................................6
1.4.4....................................................................Customizable and Beautiful UI
...............................................................................................................................................6
1.4.5..........................................................Growing Community and Ecosystem
...............................................................................................................................................6
Module 2: Environment Setup...............................................................................................................8
Module 3: Dart Programming Essentials..........................................................................................10
[Link] is Dart Programming.................................................................................................10
[Link] First Program..................................................................................................................14
[Link] Data Types in Dart..............................................................................................16
3.4Declaration and Initialization..............................................................................................16
3.5. Nullable and Non-Nullable Variables..............................................................................17
3.6 Variable Scope and Lifetime..............................................................................................17
[Link] and Immutable Variables...................................................................................17
[Link] and Var Keywords...............................................................................................18
[Link] Operators in Dart............................................................................................18
3.10....................................................................................................... If Condition
....................................................................................................................................................19
3.11.................................................................................. Logical Operators in Dart
.....................................................................................................................................................19
3.12....................................................................................... Ternary Operator (? :)
....................................................................................................................................................19
3.13.............................................................................................. Functions in Dart
....................................................................................................................................................20
Final Term 40 %
Assignments 10 %
Quizzes 10 %
Semester Project 20 %
Total: 100 %
Instead of writing separate codes for each platform, Flutter helps you save time and
effort by allowing you to reuse your code across different environments.
Real-world example: Imagine if you're building an app or software product, the goal is to
reach as many users as possible. In today's world, people use:
● Desktops/Laptops
To maximize your audience, your app needs to be available on all these platforms.
Traditional Approach: Normally, to support these platforms, developers must learn and work
with different languages and tools:
This requires different teams, different codebases, and a lot more time.
Cross-Platform with Flutter: Flutter solves this problem by allowing you to write one
codebase that works across all major platforms.
● Save time
● Reduce development costs
● Maintain only one codebase
● Ensure a consistent user experience
Native Development: Developing apps using the platform’s official languages and
tools. Example:
Hybrid Development: Hybrid apps combine web technologies (HTML, CSS, JS) inside a
native container to run as mobile apps.
- Hybrid apps often feel like websites packaged into apps, and can
sometimes suffer from performance or native feature limitations.
- The goal is to balance native performance with code reuse across platforms.
- When running on iOS, the system uses the native UIButton component.
- In Flutter:
- Flutter draws every pixel on the screen itself, making the UI fully customizable
and consistent across platforms.
Flutter provides:
● Backed by Google.
● Rich set of packages and plugins.
● Strong community support.
12
Module 3: Dart Programming Essentials
13
Android XML Java/Kotlin SQLite, Firebase
What is Dart?
● Dart is a front-end focused language used for UI development and logic building.
● It was developed by Google in 2011 to provide a better alternative to JavaScript.
● Dart is used for:
○ Mobile application development (Flutter)
○ Web development
○ Desktop applications
● Developed by Google (2011)
● Object-Oriented Programming (OOP) Language
● Strongly Typed Language (Variables must have defined data types)
● Mixture of JavaScript, Java, and C#
● Can be compiled into JavaScript (for browser execution)
● Supports AOT (Ahead-of-Time) and JIT (Just-in-Time) Compilation
● Supports Asynchronous Programming (async, await)
● Supports Flutter’s Hot Reload & Hot Restart Features
● Every variable in Dart has a defined type (e.g., int, String, double).
● Supports OOP concepts like classes, objects, inheritance, polymorphism,
abstraction, and encapsulation.
14
○ Fetching data from a server
○ Database calls
● Asynchronous programming = Parallel programming
● Dart provides async and await to handle asynchronous operations easily.
print("Fetching data...");
Output:
Fetching data...
successfully!
[Link] in Dart (AOT vs
15
AOT Compiles code before Used for final app release
(Ahead-of-Time) execution
● JIT:
○ Hot Reload & Hot Restart allow fast UI changes.
○ No need to restart the entire app after every small change.
● AOT:
○ Optimizes performance for faster app startup.
○ Used when compiling the final installable APK or iOS app.
Text("Hello World")
● Unlike React Native (JSX) or Android (XML), Flutter uses Dart for UI & logic.
● This makes Flutter development faster and reduces the learning curve.
16
3.2. Dart First Program
void main() {
runApp(MyApp());
Explanation:
● void → The return type (indicates that the function does not return any value).
● main() → The entry point of the program.
● print("Welcome to Dart"); → Prints a message to the console.
void main() {
17
● print() → Moves the cursor to the next line after displaying the message.
● [Link]() → Keeps the cursor on the same line.
import 'dart:io';
void main() {
print("Welcome, $name!");
Explanation:
If you don’t want to install an IDE, you can use DartPad (an online Dart editor).
18
Instructor: Dr. Tanzila Kehkashan
19
1. Open your browser.
2. Go to [Link].
3. Write your Dart code in the editor.
4. Click on Run to execute the code.
num Can store both int and num value = 50; or num value = 50.5;
double values
20
3.5. Nullable and Non-Nullable Variables
Nullable Variables
int? age;
● Local Variables: Declared inside a function/block and accessible only within that
block.
● Global Variables: Declared outside all functions and accessible throughout the
program.
Scope Example
void main() {
print(localVariable);
● By default, Dart variables are mutable, meaning their values can change.
21
Instructor: Dr. Tanzila Kehkashan
22
Immutable Variables (final and const)
var Keyword
Operator Meaning
== Equal to
!= Not equal to
23
>= Greater than or equal to
3.10. If Condition
Example
void main() {
int a = 100;
if (a > 200)
{
print("Block 1 executed");
} else if (a > 50) {
print("Block 2 executed");
} else if (a > 10) {
print("Block 3 executed");
} else {
print("Block 4 executed");
}
}
Output:
Block 2 executed
24
Syntax:
Example:
int a = 100;
String result = (a > 50) ? "A is large" : "A is small";
print(result);
Output:
A is large
● Return Type – Specifies what type of value the function will return (e.g.,
int, String, double, etc.). If a function doesn’t return anything, we use
void.
● Function Name – A unique identifier that is used to call the function.
● Parameters (Optional) – Input values that the function requires to perform an
operation.
● Function Body – Contains the instructions to be executed when the function is
called.
Explanation:
● The function printMessage() does not return any value, so its return type is
void.
● Inside the function body, a message is printed to the console.
● Whenever this function is called, the message "Hello, Dart!" will be displayed.
25
Instructor: Dr. Tanzila Kehkashan
26
Output:
Hello, Dart!
Explanation:
● The function add(int a, int b) takes two integer parameters and returns
their sum.
● The return type is int, so we must return an integer value.
● The return statement sends the result back to the calling function.
Output:
void main() {
greet("Nawaz");
27
Instructor: Dr. Tanzila Kehkashan
28
greet("Kandan");
}
Output:
Hello,
Nawaz!
Hello,
Kandan!
void main() {
double area = calculateArea(5);
print("The area is: $area");
}
Output:
void main() {
greetCR("Faisal");
greetCR("Nawaz");
}
29
Function Without Parameters but With Return Type
30
int getRandomNumber() {
return 42;
}
void main() {
int number = getRandomNumber();
print("Random number is:
$number");
}
Passing Arguments to Functions
void main() {
displayInfo("Sohaib", 25);
}
Output:
void main() {
showDetails("Umair");
showDetails("Adil", 30);
}
31
Named Parameters with Default Values
void introduce({String name = "Guest", int age = 18})
{ print("Name: $name, Age: $age");
}
void main() {
introduce();
introduce(name: "Imran", age: 25);
}
void sayHello() {
print("Hello from a function!");
}
void main() {
executeFunction(sayHello);
}
functions.
void main() {
print(add(3, 5)); // Output: 8
}
without a name.
32
Instructor: Dr. Tanzila Kehkashan
33
A List in Dart is an ordered collection of objects. Lists are similar to arrays in other
programming languages and allow storing multiple values in a single variable.
Creating Lists
void main() {
List<int> numbers = [Link](5, 0); // Creates a list of size 5
with default values 0
numbers[0] = 10;
numbers[1] = 20;
print(numbers); // Output: [10, 20, 0, 0, 0]
}
void main() {
List<String> fruits = ["Apple", "Banana", "Cherry"];
[Link]("Mango"); // Adding a new element
print(fruits); // Output: [Apple, Banana, Cherry, Mango]
}
List Properties
void main() {
List<int> numbers = [1, 2, 3, 4, 5];
List Methods
34
i. Adding Elements
void main() {
List<int> numbers = [1, 2, 3];
[Link] Elements
void main() {
List<String> cars = ["BMW", "Tesla", "Toyota"];
Mercedes
[Link] Elements
void main() {
List<int> numbers = [10, 20, 30, 40];
35
print([Link](20)); // Output: true (checks if 20 exists)
print([Link](30)); // Output: 2 (returns index of 30)
}
v. Sorting a List
void main() {
List<int> numbers = [5, 2, 9, 1, 7];
print([Link]());
}
// Output:
// New York
// London
// Paris
}
36
List<int> squaredNumbers = [Link]((num) => num *
Dart Maps are a powerful way to store key-value pairs and provide various methods
for easy manipulation. They are essential when working with structured data in
Flutter and Dart applications.
Creating a Map
37
Instructor: Dr. Tanzila Kehkashan
38
void main() {
Map<String, int> ages = {
"Haseeb": 25,
"Umer": 30,
"Zaka": 35
};
Accessing Elements
void main() {
Map<String, int> scores = {"Fahad": 90, "Umair": 85, "Arslan": 95};
print(scores["Fahad"]); // Output: 90
print(scores["Imran"]); // Output: null (key not found)
}
39
marks["Science"] = 95; // Updating an existing key
Removing Elements
void main() {
Map<String, int> scores = {"Fahad": 90, "Umair": 85, "Arslan": 95};
i. Using forEach()
void main() {
Map<String, int> marks = {"Math": 90, "Science": 85, "English": 88};
[Link]((subject, mark) {
print("$subject: $mark");
});
}
Output:
Math: 90
40
Science: 85
English: 88
UK → London
Pakistan → Islamabad
Map Properties
void main() {
Map<String, int> numbers = {"One": 1, "Two": 2, "Three": 3};
Sorting a Map
void main() {
Map<String, int> students = {"Fahad": 90, "Umair": 85, "Arslan": 95};
41
print(sortedMap); // Output: {Arslan: 95, Fahad: 90, Umair: 85}
}
Filtering a Map
void main() {
Map<String, int> marks = {"Math": 90, "Science": 70, "English": 85};
42
class Car {
// Instance Variables (Properties)
String brand;
int year;
double price;
// Constructor
Car([Link], [Link], [Link]);
void main() {
// Creating Objects of Car Class
Car car1 = Car("Toyota", 2022, 25000);
Car car2 = Car("Honda", 2023, 28000);
// Calling Methods
[Link]();
[Link]();
}
Output:
Price: $28000
class Person {
String name = "Ali Raza Jatala"; // Default value
43
Instructor: Dr. Tanzila Kehkashan
44
void showName() {
print("Person's Name: $name");
}
}
void main() {
Person p = Person(); // Default constructor
[Link]();
}
class Student {
String name;
int age;
// Parameterized Constructor
Student([Link], [Link]);
}
void main() {
Student s1 = Student("Kandan", 20); print("$
{[Link]} is ${[Link]} years old");
}
class Employee
{ String name;
int salary;
// Default Constructor
Employee([Link], [Link]);
// Named Constructor
[Link]([Link], [Link])
{
salary += 5000; // Adding Bonus
45
}
}
void main() {
Employee e1 = Employee("Haseeb", 50000);
Employee e2 = [Link]("Umer", 50000);
Output:
class Product {
String _name = ""; // Private Variable
// Getter
String get name => _name;
// Setter
set name(String value) {
if ([Link]) {
_name = value;
}
}
}
void main() {
Product p = Product();
[Link] = "Laptop"; // Using
Setter print([Link]); // Using
Getter
46
Inheritance in Dart (Extending a Class)
Inheritance allows a child class to reuse properties and methods from a parent class.
class Animal {
void makeSound()
{
print("Animal makes a sound");
}
}
void main()
{ Dog d =
Dog();
[Link](); // Inherited
Output:
Dog Barks
An abstract class cannot be instantiated and is used to define a blueprint for other
classes.
47
Instructor: Dr. Tanzila Kehkashan
48
}
}
void main() {
Circle c = Circle();
[Link]();
}
Polymorphism in Dart
class Animal {
void makeSound()
{
print("Animal makes a sound");
}
}
void main()
{ Animal a =
Cat();
Output:
Cat Meows
static properties and methods belong to the class itself, not individual objects.
class MathUtils {
static const double pi = 3.1416;
49
static double square(double num) {
return num * num;
}
}
void main() {
print("Pi Value: ${[Link]}");
print("Square of 4: ${[Link](4)}");
}
50
Module 4: Flutter Basics - UI Components & Widgets
4.1. Flutter Widgets Overview
51
4.6. State Management Overview (Stateless vs Stateful Widgets)
52