1 / 34
Start
Git
GitHub
Branch
PR
Workflow
Project
G1
G2
G3
G4
Merge
Classes
Anatomy
Order
Extend
Q1
Q2
Q3
RestApp
Project
Week 2 · Day 4

Git, Teamwork &
Classes

Learn how real teams build software together. Then organize your code with classes.

Git Basics GitHub Branches Pull Requests Lists & Functions Team Project Classes Constructors Methods Extending 2 Quizzes + Project

Press J anytime to jump to any section. Arrow keys to navigate.

Topic 1 · Git

What is Git?

🎮

Git = Save Points in a Video Game

Imagine you're playing a game. You save before fighting a boss. If you lose, you go back to the save point. Git does the SAME thing for your code.

😱 Without Git: You change code → it breaks → you lost everything
With Git: You save (commit) → change code → it breaks → go back to save point
💾
💾
Save 1
"Started project"
💾
Save 2
"Added menu"
💾
Save 3
"Added prices"
▲ YOU ARE HERE

Each save is called a commit. Git remembers EVERY save you ever made.

📌 Git = a time machine for your code. You can always go back.

Topic 1 · Git

Your First Git Commands

Just 4 commands to start. That's it.

git init

📂 Start tracking — Like opening a new notebook. "I want to track this project."

git add menu.dart

📦 Pick what to save — Like highlighting the pages you want to photocopy.

git commit -m "added menu items"

💾 Save point! — Take a snapshot. The message says WHAT you did.

git status

🔍 What changed? — "Show me what files I changed since last save."

📌 Workflow: change code → git addgit commit. Repeat.

Topic 2 · GitHub

What is GitHub?

☁️

GitHub = Google Drive for Code

Git lives on YOUR computer. But what if your laptop breaks? What if your teammate needs the code? GitHub stores your code ONLINE so everyone can access it.

💻
Your Computer
push →
← pull
☁️
GitHub (online)

push = upload your code to GitHub

pull = download the latest code from GitHub

git push // Send your saves to GitHub
git pull // Get your team's latest saves

📌 Git = saves on your computer. GitHub = saves in the cloud that everyone can see.

Topic 2 · GitHub

Branches — Parallel Copies

🌳

Branch = A Copy Where You Try New Things

Imagine a restaurant's recipe book. The main book has all the tested recipes. You want to try a new momo recipe? Make a copy (branch), experiment there. If it's good, add it back to the main book.

main
feature/new-momo
merge ✓
git branch feature/new-momo // Create a copy
git checkout feature/new-momo // Switch to it
// ... make changes, commit ...
git checkout main // Go back to main
git merge feature/new-momo // Add your changes to main

📌 Always create a branch for new features. Never mess with main directly.

Topic 3 · Teamwork

Pull Requests — Ask Before Merging

📝

Pull Request = Asking Permission

In a company, you don't just add your recipe to the main book. You say: "Hey team, I made a new momo recipe. Can you check it before I add it?" That's a Pull Request (PR).

1. 💻 You finish your code on your branch
2. 📝 Create a Pull Request on GitHub
3. 👀 Teammate reads your code (Code Review)
4. ✅ They approve or ask for changes 🔄
5. 🎉 Merge into main!

📌 In real companies, NO code goes to main without a Pull Request. This protects the project.

Topic 3 · Teamwork

Code Review — Learning From Each Other

What reviewers look for

✅ Does the code work?
✅ Is it easy to read?
✅ Are variable names clear?
✅ Is there anything missing?
✅ Can it be simpler?

How to give good feedback

❌ Bad: "This is wrong"
✅ Good: "Maybe rename 'x' to 'price'? It's clearer"
❌ Bad: "I don't like this"
✅ Good: "What if we split this into two functions?"
❌ Bad: No comment at all
✅ Good: "Looks great! Just one small thing..."

📌 Code review is not about criticism. It's about making the code better TOGETHER.

Topic 2 · GitHub

.gitignore — What NOT to Share

🚫

Not everything should go to GitHub.

Passwords, big files, system junk — keep them private.

.gitignore file

# Don't push these:
.DS_Store # Mac system file
node_modules/ # Downloaded packages
.env # Passwords & secrets
*.log # Log files
build/ # Compiled code
.dart_tool/ # Dart internal files

Why?

🔑 .env — Has passwords. Never share!
📦 node_modules/ — Everyone downloads their own
🗑️ .DS_Store — Mac junk, nobody needs it
🏗️ build/ — Can be regenerated

📌 Create .gitignore BEFORE your first commit. Rule: if it's generated or secret, ignore it.

Topic 3 · Teamwork

Real Company Workflow

This is how teams at companies like eSewa, Khalti, and Daraz actually build software.

📋 Task assigned: "Add momo to menu"
🌿 Create branch: feature/add-momo
💻 Write code on your branch
💾 git add → git commit (save often!)
⬆️ git push (upload to GitHub)
📝 Create Pull Request
👀 Teammate reviews your code
Approved → Merge to main
🚀 Deploy! Users see the new feature

📌 This is EXACTLY what you'll do today with your team project.

🎮 Quiz 1 · Git & GitHub

Test Your Git Knowledge

1. What is a commit?

ADeleting code
BA save point for your code
CUploading to GitHub
✅ A commit is a save point. It captures a snapshot of your code at that moment.

2. What does git push do?

ASaves locally
BCreates a branch
CUploads your commits to GitHub
✅ git push uploads your local commits to GitHub so others can see them.

3. Why use Pull Requests?

ATo delete branches
BSo teammates can review before merging
CTo download code
✅ Pull Requests let teammates check your code before it goes into the main project.
🎮 Team Project · Nepali Restaurant

Build a Restaurant Menu App

4 groups. 1 restaurant. Each group builds one part. Then we combine everything.

🏪 Nepali Bhojanalaya (Restaurant)
📋 Menu Group 1
🛒 Orders Group 2
💰 Billing Group 3
🔎 Search Group 4

Each group works on their OWN branch. Then we merge everything together. Just like a real company.

Team Project · Setup

The Starter Code

Everyone starts with this. It's the restaurant's basic data.

// menu_data.dart — everyone uses this

var menuItems = ['Momo', 'Dal Bhat', 'Chowmein',
'Samosa', 'Thukpa', 'Sekuwa',
'Sel Roti', 'Chatamari'];

var prices = {
'Momo': 120,
'Dal Bhat': 150,
'Chowmein': 100,
'Samosa': 60,
'Thukpa': 130,
'Sekuwa': 200,
'Sel Roti': 40,
'Chatamari': 160,
};
var categories = {
'Momo': 'snack',
'Dal Bhat': 'main',
'Chowmein': 'snack',
'Samosa': 'snack',
'Thukpa': 'main',
'Sekuwa': 'main',
'Sel Roti': 'dessert',
'Chatamari': 'main',
};
git clone <repo-url>
git checkout -b feature/your-group-name
Group 1 · Menu System

📋 Build the Menu Display

Your job: show the menu in different ways.

// Build these functions:

void showFullMenu() {
// Print all items with prices
// "1. Momo — Rs.120"
// "2. Dal Bhat — Rs.150"
}

List<String> filterByCategory(String category) {
// Return items matching category
// filterByCategory('snack')
// → ['Momo','Chowmein','Samosa']
}

void showMenuByCategory() {
// Print menu grouped by category
// === SNACKS ===
// Momo — Rs.120
}

Expected Output

=== FULL MENU ===
1. Momo — Rs.120
2. Dal Bhat — Rs.150
3. Chowmein — Rs.100
...

=== SNACKS ===
Momo — Rs.120
Chowmein — Rs.100
Samosa — Rs.60
git add menu.dart
git commit -m "feat: add menu display functions"
git push origin feature/menu
Group 2 · Order System

🛒 Build the Order System

List<String> currentOrder = [];

void addToOrder(String item) {
// Add item to currentOrder
// Print "Added Momo to order"
// If not in menu: "Item not found!"
}

void removeFromOrder(String item) {
// Remove item from currentOrder
// Print "Removed Momo from order"
}

void showOrder() {
// Print current order
// "Your Order:"
// "1. Momo"
// "Total items: 2"
}

void clearOrder() {
// Empty the order
// Print "Order cleared!"
}

Expected Output

> Added Momo to order
> Added Dal Bhat to order
> Added Momo to order

Your Order:
1. Momo
2. Dal Bhat
3. Momo
Total items: 3
Group 3 · Billing System

💰 Build the Billing System

int calculateTotal(List<String> order) {
// Add up prices of all items
// return total
}

double applyDiscount(int total, double percent) {
// Apply discount, return new total
// applyDiscount(500, 10) → 450.0
}

double applyTax(double amount) {
// Add 13% tax (Nepal VAT)
// applyTax(450) → 508.5
}

void generateBill(List<String> order) {
// Print a complete bill:
// Item list with prices
// Subtotal, Discount, Tax
// Grand Total
}

Expected Output

=== YOUR BILL ===
Momo Rs.120
Dal Bhat Rs.150
Momo Rs.120
-----------------
Subtotal: Rs.390
Discount(10%): -Rs.39
After discount: Rs.351
Tax(13%): Rs.45.63
-----------------
TOTAL: Rs.396.63
Group 4 · Search & Filter

🔎 Build Search & Filter

List<String> searchItem(String query) {
// Find items containing the query
// searchItem('mo') → ['Momo']
}

String findCheapest() {
// Return the cheapest item
// "Sel Roti — Rs.40"
}

String findMostExpensive() {
// Return the most expensive item
// "Sekuwa — Rs.200"
}

List<String> filterByPrice(int maxPrice) {
// Return items under maxPrice
// filterByPrice(100) →
// ['Samosa', 'Sel Roti']
}

Map<String,int> sortByPrice() {
// Return prices sorted cheap → expensive
}

Expected Output

> Search 'mo': [Momo]
> Cheapest: Sel Roti — Rs.40
> Most Expensive: Sekuwa — Rs.200
> Under Rs.100: [Samosa, Sel Roti]
Team Project · Merge

Merge Day — Combining All Features

feature/menu
→ PR → ✅ Merge
feature/order
→ PR → ✅ Merge
feature/billing
→ PR → ✅ Merge
feature/search
→ PR → ✅ Merge
main (complete app!) 🎉
1. Each group creates a Pull Request
2. Another group reviews your PR
3. Approved → Merge!
4. Everyone pulls the latest:
git checkout main
git pull
5. Now everyone has the FULL restaurant app!
🎮 Interactive · Complete Restaurant

The Complete Restaurant App

All 4 groups' code combined. Click each feature.

📋 Menu
🛒 Order
💰 Bill
🔎 Search
CONCEPTS USED
🎮 Quiz 2 · Lists & Functions

Test Your Code Skills

1. What does menuItems.where((item) => prices[item]! > 100).toList() return?

AAll items
BItems with price over 100
CPrices over 100
✅ .where() filters items. It keeps only items where price > 100.

2. What does .fold(0, (sum, x) => sum + x) do?

AFinds the first item
BAdds all values together
CRemoves items
✅ fold starts at 0 and adds each value. It's like a running total.

3. Why do we write prices[item] ?? 0 with ???

AIt's faster
BIn case the item isn't in the map, use 0 as default
CIt adds 0 to the price
✅ ?? means "if null, use this instead". It's a safety net for missing keys.
Topic 4 · Classes

Our Code is Getting Messy

// One menu item needs 3 separate variables:
var name1 = 'Momo';
var price1 = 120;
var category1 = 'snack';

var name2 = 'Dal Bhat';
var price2 = 150;
var category2 = 'main';

// 8 items × 3 variables = 24 variables!
// What if we add description?
// Spicy level? Rating?
// It gets WORSE with every new field.
😱

This doesn't scale.

We need a better way to organize our data.

Topic 4 · Classes

What is a Class?

📋

Class = A Form Template

Think about ordering at a restaurant. The waiter has a blank ORDER FORM. Every customer gets the SAME form, but fills in DIFFERENT items. The form is the CLASS. Each filled form is an OBJECT.

📋 Order Form (CLASS)
Name: ________
Items: ________
Total: ________
↓ ↓
📋 Aayush's Order (OBJECT)
Name: Aayush
Items: Momo, Tea
Total: Rs.150
📋 Sita's Order (OBJECT)
Name: Sita
Items: Dal Bhat
Total: Rs.150

One template → many filled copies. That's classes and objects!

Topic 4 · Classes

Anatomy of a Class

class MenuItem { // ← Class name (blueprint)
// Properties — what it HAS
String name; // ← data it holds
int price;
String category;

// Constructor — how to CREATE it
MenuItem(this.name, this.price, this.category);

// Method — what it can DO
String getInfo() {
return '$name — Rs.$price ($category)';
}
}
// Create objects (filled forms!)
var momo = MenuItem('Momo', 120, 'snack');
var dalBhat = MenuItem('Dal Bhat', 150, 'main');

print(momo.name); // Momo
print(momo.price); // 120
print(momo.getInfo()); // Momo — Rs.120 (snack)
📦
Properties
what it HAS
🔨
Constructor
how to BUILD it
Methods
what it can DO
Topic 4 · Classes

MenuItem — From Messy to Clean

❌ BEFORE: Messy variables
var name1 = 'Momo';
var price1 = 120;
var cat1 = 'snack';

var name2 = 'Dal Bhat';
var price2 = 150;
var cat2 = 'main';

// Hard to pass around
// Hard to manage
✅ AFTER: Clean classes
var menu = [
MenuItem('Momo', 120, 'snack'),
MenuItem('Dal Bhat', 150, 'main'),
MenuItem('Chowmein', 100, 'snack'),
MenuItem('Samosa', 60, 'snack'),
MenuItem('Thukpa', 130, 'main'),
];

// Easy to loop, filter, pass around!
for (var item in menu) {
print(item.getInfo());
}

// Filter snacks
var snacks = menu
.where((m) => m.category == 'snack')
.toList();

📌 One object = one thing. No more scattered variables.

Topic 5 · More Classes

Order Class — Organizing Orders

class Order {
String customerName;
List<MenuItem> items;

Order(this.customerName) : items = [];

void addItem(MenuItem item) {
items.add(item);
print('✅ Added ${item.name} for $customerName');
}

void removeItem(String itemName) {
items.removeWhere((item) => item.name == itemName);
print('🗑 Removed $itemName');
}

int getTotal() {
return items.fold(0, (sum, item) => sum + item.price);
}

void showOrder() {
print('Order for $customerName:');
for (var item in items) {
print(' ${item.name} — Rs.${item.price}');
}
print('Total: Rs.${getTotal()}');
}
}

USAGE

var order = Order('Aayush');
order.addItem(momo);
// ✅ Added Momo for Aayush
order.addItem(dalBhat);
// ✅ Added Dal Bhat for Aayush
order.showOrder();
// Order for Aayush:
// Momo — Rs.120
// Dal Bhat — Rs.150
// Total: Rs.270
Topic 5 · More Classes

Constructors — Different Ways to Build

class MenuItem {
String name;
int price;
String category;

// 1. Default constructor
MenuItem(this.name, this.price, this.category);

// 2. Named constructor — special menu item
MenuItem.special(this.name, this.price)
: category = 'special';

// 3. Named constructor — free item (promo!)
MenuItem.freebie(this.name)
: price = 0, category = 'promo';
}

// Use them:
var momo = MenuItem('Momo', 120, 'snack'); // normal
var todaySpecial = MenuItem.special('Buff Momo', 180); // special
var freeWater = MenuItem.freebie('Water'); // free!

📌 Named constructors = shortcuts. MenuItem.special() is clearer than passing lots of parameters.

Topic 5 · More Classes

Methods — Adding Superpowers

class Order {
// ... previous code ...

bool hasItem(String name) {
return items.any((item) => item.name == name);
}

MenuItem? getMostExpensive() {
if (items.isEmpty) return null;
return items.reduce(
(a, b) => a.price > b.price ? a : b);
}

String getBill({double discount = 0}) {
var subtotal = getTotal();
var disc = (subtotal * discount / 100).round();
var tax = ((subtotal - disc) * 0.13).round();
var total = subtotal - disc + tax;
return '''
=== BILL ===
Customer: $customerName
Items: ${items.length}
Subtotal: Rs.$subtotal
Discount: -Rs.$disc
Tax(13%): Rs.$tax
TOTAL: Rs.$total
''';
}
}

USAGE

order.hasItem('Momo'); // true
order.getMostExpensive(); // Dal Bhat
print(order.getBill(discount: 10));
// === BILL ===
// Customer: Aayush
// Items: 2
// Subtotal: Rs.270
// Discount: -Rs.27
// Tax(13%): Rs.32
// TOTAL: Rs.275
🎮 Quiz 3 · Classes

Test Your Class Knowledge

1. What's the difference between a class and an object?

ANo difference
BClass is the blueprint, object is the thing built from it
CObject is the blueprint
✅ A class is the template (like the order form). An object is a filled-in copy.

2. What does MenuItem(this.name, this.price, this.category) do?

ADeletes the class
BCreates a constructor that sets all properties
CCalls a method
✅ this.name means "set the property name to whatever value is passed in".

3. When would you use MenuItem.special('Buff Momo', 180)?

ATo delete an item
BWhen you want a shortcut to create a specific type of item
CTo extend the class
✅ Named constructors are shortcuts. They pre-fill some values so you type less.
Topic 6 · Inheritance

Extending — Build On Top

🏠

SpecialOrder IS an Order... with extra features.

Like a house with an extra floor built on top. You keep everything below and add more.

class SpecialOrder extends Order {
double discountPercent;

SpecialOrder(String customerName, this.discountPercent)
: super(customerName); // call parent constructor

@override
String getBill({double discount = 0}) {
// Use our special discount instead
return super.getBill(discount: discountPercent);
}

void addFreeItem(MenuItem item) {
var freeVersion = MenuItem.freebie(item.name);
items.add(freeVersion);
print('🎁 FREE ${item.name} for $customerName!');
}
}

var vipOrder = SpecialOrder('Sita', 20); // 20% discount
vipOrder.addItem(momo);
vipOrder.addFreeItem(MenuItem('Water', 0, 'drink'));
print(vipOrder.getBill());

📌 extends = "is a". SpecialOrder IS an Order with extra powers. super calls the parent.

Topic 6 · Inheritance

@override — Change Behavior

A child class can change how a parent's method works.

class TakeawayOrder extends Order {
double packagingFee;

TakeawayOrder(String customerName,
{this.packagingFee = 30})
: super(customerName);

@override
int getTotal() {
var itemsTotal = super.getTotal();
return itemsTotal + packagingFee.round();
}

@override
void showOrder() {
super.showOrder();
print('📦 Packaging: Rs.$packagingFee');
print('Grand Total: Rs.${getTotal()}');
}
}

OUTPUT

var takeaway = TakeawayOrder('Ram');
takeaway.addItem(momo);
takeaway.showOrder();
// Order for Ram:
// Momo — Rs.120
// Total: Rs.120
// 📦 Packaging: Rs.30
// Grand Total: Rs.150

📌 @override = same method name, different behavior. super.method() calls the original version.

🎮 Project · Restaurant System

Complete Restaurant System

Everything from today — classes, methods, extending. Click each feature.

📋 MenuItem
🛒 Order
💳 Bill
⭐ VIP Order
🖨 Full Demo
CONCEPTS USED
Summary

Everything We Learned Today

Git Basics

init, add, commit, status

GitHub

push, pull, remote repos

Branches & PRs

branch, merge, pull requests, code review

Lists & Maps

where, map, fold, chaining

Functions

closures, pure functions, HOF

Classes

blueprint, properties, constructor, methods

Constructors

default, named, shortcuts

Methods

getTotal, showOrder, getBill

Inheritance

extends, super, @override

Assignment

Take-Home: Improve Your Restaurant

1. Add at least 5 more menu items to your team's project
2. Add a "rating" property to MenuItem (1-5 stars)
3. Create a filterByRating(int minRating) method
4. Add a TakeawayOrder class that adds Rs.30 packaging fee
5. Create a printReceipt() method with nice formatted output
6. Push to your flutter-tr06 repo with meaningful commit messages

Use branches! Create feature/your-name and submit a PR.

Coming Next

Day 5 Preview

More OOP Abstract Classes Async/Await Error Handling

Before next class: Practice making PRs on your team repo.

Any Questions?

Practice at dartpad.dev — build your own classes!