W25 - BSCS-7 / BSSE-7: Dr. Tanzila Kehkashan
W25 - BSCS-7 / BSSE-7: Dr. Tanzila Kehkashan
MADT-4118
Instructor
Dr. Tanzila Kehkashan
UOL-Sgd
1
Module 1: Introduction to Mobile Application Development.............................................................3
1.1. Assessment & Evaluation Criteria.................................................................................... 3
1.2. What is Flutter?.................................................................................................................3
Key Concept: Cross-Platform Development...................................................................... 3
Why is Cross-Platform Development Important?...............................................................3
1.1 Understanding Key Terms............................................................................................4
1.2 How is Flutter Different from Other Cross-Platform Tools?................................................5
Advantages of Flutter’s Rendering.......................................................................................... 5
1.4 Benefits 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
3.1. What is Dart Programming............................................................................................. 10
3.2. Dart First Program.......................................................................................................... 14
3.3. Common Data Types in Dart.......................................................................................... 16
3.4 Declaration and Initialization............................................................................................16
3.5. Nullable and Non-Nullable Variables.............................................................................. 17
3.6 Variable Scope and Lifetime............................................................................................ 17
3.7. Mutable and Immutable Variables.................................................................................. 17
3.8. Dynamic and Var Keywords............................................................................................18
3.9. Conditional 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
3.14. Lists in Dart...................................................................................................................24
3.15. Maps in Dart................................................................................................................. 28
3.16. OOP in Dart.................................................................................................................. 32
Module 4: Flutter Basics - UI Components & Widgets...........................................................39
4.1. Flutter Widgets Overview................................................................................................39
4.2. Text, Buttons, and Image Widgets.................................................................................. 39
4.3. Layouts: Rows, Columns & Stack...................................................................................39
4.4. Navigation & Routing in Flutter....................................................................................... 39
4.5. User Input Handling & Forms......................................................................................... 39
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
● Mobile phones (Android & iOS)
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:
- Native development means apps are optimized specifically for that platform, but require
separate codebases for each platform.
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.
Cross-Platform Development: Write your app’s code once and run it on multiple platforms.
- 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.
10
Module 3: Dart Programming Essentials
● Flutter is a framework used for app development, but the programming language behind
it is Dart.
● Without understanding Dart, it would be difficult to develop apps in Flutter.
● Dart provides both UI development and backend logic in Flutter.
● Learning Dart first makes Flutter development easier and more efficient.
● Unlike Android or Web Development, Flutter uses only one language—Dart, making
development simpler and faster.
11
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.
12
○ 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...
What is a Compiler?
JIT (Just-in-Time) Compiles code at runtime Used during development (Hot Reload,
Hot Restart)
13
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")
● If changed to "Hello Flutter" and hot reloaded, the UI updates instantly without
restarting the app.
● Unlike React Native (JSX) or Android (XML), Flutter uses Dart for UI & logic.
● This makes Flutter development faster and reduces the learning curve.
14
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() {
15
● print() → Moves the cursor to the next line after displaying the message.
● stdout.write() → 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).
16
1. Open your browser.
2. Go to dartpad.dev.
3. Write your Dart code in the editor.
4. Click on Run to execute the code.
num Can store both int and double num value = 50; or num value = 50.5;
values
17
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.
18
Immutable Variables (final and const)
var Keyword
dynamic Keyword
Operator Meaning
== Equal to
!= Not equal to
19
>= 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
20
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.
21
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");
22
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");
}
23
int getRandomNumber() {
return 42;
}
void main() {
int number = getRandomNumber();
print("Random number is: $number");
}
void main() {
displayInfo("Sohaib", 25);
}
Output:
void main() {
showDetails("Umair");
showDetails("Adil", 30);
}
24
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);
}
void main() {
print(add(3, 5)); // Output: 8
}
25
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 = List.filled(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"];
fruits.add("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
26
i. Adding Elements
void main() {
List<int> numbers = [1, 2, 3];
27
print(numbers.contains(20)); // Output: true (checks if 20 exists)
print(numbers.indexOf(30)); // Output: 2 (returns index of 30)
}
v. Sorting a List
void main() {
List<int> numbers = [5, 2, 9, 1, 7];
print(names.reversed.toList());
}
// Output:
// New York
// London
// Paris
}
28
List<int> squaredNumbers = numbers.map((num) => num * num).toList();
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
29
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)
}
30
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};
marks.forEach((subject, mark) {
print("$subject: $mark");
});
}
Output:
Math: 90
31
Science: 85
English: 88
Output:
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};
32
print(sortedMap); // Output: {Arslan: 95, Fahad: 90, Umair: 85}
}
Filtering a Map
void main() {
Map<String, int> marks = {"Math": 90, "Science": 70, "English": 85};
33
class Car {
// Instance Variables (Properties)
String brand;
int year;
double price;
// Constructor
Car(this.brand, this.year, this.price);
void main() {
// Creating Objects of Car Class
Car car1 = Car("Toyota", 2022, 25000);
Car car2 = Car("Honda", 2023, 28000);
// Calling Methods
car1.showDetails();
car2.showDetails();
}
Output:
If no constructor is defined, Dart provides a default constructor that initializes objects without
parameters.
class Person {
String name = "Ali Raza Jatala"; // Default value
34
void showName() {
print("Person's Name: $name");
}
}
void main() {
Person p = Person(); // Default constructor
p.showName();
}
class Student {
String name;
int age;
// Parameterized Constructor
Student(this.name, this.age);
}
void main() {
Student s1 = Student("Kandan", 20);
print("${s1.name} is ${s1.age} years old");
}
class Employee {
String name;
int salary;
// Default Constructor
Employee(this.name, this.salary);
// Named Constructor
Employee.withBonus(this.name, this.salary) {
salary += 5000; // Adding Bonus
35
}
}
void main() {
Employee e1 = Employee("Haseeb", 50000);
Employee e2 = Employee.withBonus("Umer", 50000);
Output:
class Product {
String _name = ""; // Private Variable
// Getter
String get name => _name;
// Setter
set name(String value) {
if (value.isNotEmpty) {
_name = value;
}
}
}
void main() {
Product p = Product();
p.name = "Laptop"; // Using Setter
print(p.name); // Using Getter
}
36
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();
d.makeSound(); // Inherited Method
d.bark(); // Dog's Own Method
}
Output:
Dog Barks
An abstract class cannot be instantiated and is used to define a blueprint for other classes.
37
}
}
void main() {
Circle c = Circle();
c.draw();
}
Polymorphism in Dart
class Animal {
void makeSound() {
print("Animal makes a sound");
}
}
void main() {
Animal a = Cat();
a.makeSound(); // Calls overridden method
}
Output:
Cat Meows
static properties and methods belong to the class itself, not individual objects.
class MathUtils {
static const double pi = 3.1416;
38
static double square(double num) {
return num * num;
}
}
void main() {
print("Pi Value: ${MathUtils.pi}");
print("Square of 4: ${MathUtils.square(4)}");
}
39
Module 4: Flutter Basics - UI Components & Widgets
4.1. Flutter Widgets Overview
40
4.6. State Management Overview (Stateless vs Stateful Widgets)
41