1 / 36
Start
Project
App Shell
Anatomy
Widgets
Layout
Custom
State
Wireframe
Week 4 · Day 8

From Dart to Flutter

Same Dart you know. New superpower — pixels on a screen. Today: your first real UI.

Widgets MaterialApp CupertinoApp Layouts setState First Flutter Day

Press J to jump. Arrow keys to navigate.

Bridge · Step 1

You already know Dart.

7 days of variables, functions, classes, async. That's the language. Now we add the toolkit.

Variables

int, String, bool, List, Map

Functions

Define once, call anywhere

Classes

Blueprints for objects

async / await

Wait for slow stuff

Streams

Many values over time

Packages

Code from pub.dev

Bridge · Step 2

Flutter is a UI toolkit on top of Dart.

Dart runs the logic. Flutter draws the screen.

๐Ÿ“œ

Dart

The language

๐ŸŽจ

Flutter

The UI toolkit

๐Ÿ“ฑ

App

Real pixels

The Big Idea

Everything is a widget.

Text? Widget. Button? Widget. Padding? Widget. Even the screen itself? Widget. They nest inside each other like LEGO.

๐Ÿ“ฑ Screen
๐Ÿ“ Text
๐Ÿ”˜ Button
๐Ÿ–ผ๏ธ Image
๐Ÿ“ฆ Container

If you wonder "is this a widget?" — yes.

Project · Step 1

Make a project: flutter create

One command. Done. Flutter writes ~30 files for you.

$ flutter create my_first_app
$ cd my_first_app
$ flutter run
๐Ÿ“ฆ

Create

Scaffold the project

๐Ÿ“‚

cd in

Move into the folder

โ–ถ๏ธ

Run

Boot on your phone

Project · Step 2

Folder tour

Don't panic. You'll mostly live in lib/.

๐Ÿ“ my_first_app/
๐Ÿ“ lib/ ← you write code here
๐Ÿ“„ main.dart ← the entry point
๐Ÿ“„ pubspec.yaml ← packages + config
๐Ÿ“ android/ ← native Android (rarely touch)
๐Ÿ“ ios/ ← native iOS (rarely touch)
๐Ÿ“ test/ ← tests go here
Project · Step 3

main.dart — the start line

Like every Dart program, Flutter starts at main(). Inside, one magic line: runApp(...).

void main() {
  runApp(MyApp());
}

runApp takes one widget and paints it on the whole screen. That widget is your app.

App Shell

Two flavors: Material vs Cupertino

The wrapper that gives your app its look. Pick one based on the platform you want to feel native on.

Android-style
My App
Material card

MaterialApp

Google's design

iOS-style
My App
Cupertino tile

CupertinoApp

Apple's design

App Shell · Material

MaterialApp — the default

Most Flutter apps use this. Bold colors, raised buttons, hamburger menus. Looks at home on Android.

๐ŸŽจ

Themes

Colors, fonts, spacing — one place

๐Ÿงญ

Routes

Screen-to-screen navigation

๐Ÿ“š

Widgets

AppBar, Scaffold, Drawer, FAB

When in doubt, start with MaterialApp. You can always switch later.

App Shell · Cupertino

CupertinoApp — the iOS feel

Soft corners, gentle blur, sliding screens. Feels native on iPhone. Optional — only use if your app is iOS-first.

๐ŸŽ

iOS feel

Looks & behaves like iPhone apps

โ†ช๏ธ

Swipe back

Native iOS gestures built-in

๐ŸŽฏ

Cupertino*

CupertinoButton, CupertinoNavigationBar...

App Shell · Decide

Which one for you?

Pick MaterialApp

โœ“ Cross-platform app
โœ“ Android-first
โœ“ You're new to Flutter
โœ“ You want one look everywhere

Pick CupertinoApp

โœ“ iOS-only release
โœ“ App must feel iPhone-native
โœ“ You're cloning an iOS app
โœ“ Apple Store is the priority

90% of beginners go with MaterialApp. We will too.

Anatomy · Step 1

Apps are trees of widgets.

A parent widget holds children. Children hold their own children. Goes deep.

MaterialApp
Scaffold
AppBar
Body
Text
Button
Anatomy · Step 2

The build() method

Every widget has a build(). Inside, it returns more widgets. That's how the tree grows.

class MyApp extends StatelessWidget {
  Widget build(context) {
    return Text('Hello!');
  }
}

Think of build() as: "draw me. given the current context, here's what I look like."

Anatomy · Step 3

BuildContext — "where am I?"

Every widget gets a context. It's a handle that says "here's your spot in the tree." Use it to find parents, themes, screen size.

๐Ÿ“

Position

Where in tree

๐ŸŽจ

Theme.of(ctx)

Get colors, fonts

๐Ÿ“

MediaQuery

Screen size

Don't memorize. You'll just keep typing context and Flutter figures it out.

Big Picture

Code → pixels in 4 steps

Simple version. Skip the engine internals.

๐Ÿ“

1. You write

Dart + widgets

โ†’
๐ŸŒณ

2. Tree

Flutter builds tree

โ†’
๐ŸŽจ

3. Paint

Engine draws

โ†’
๐Ÿ“ฑ

4. Screen

You see pixels

Built-in Widgets · 1/3

Show stuff: Text, Icon, Image

Display-only widgets. They show, they don't react.

Hello!

Text

Words on screen

โญ

Icon

Built-in symbols

Image

Photos & assets

Built-in Widgets · 2/3

Shape & spacing: Container, SizedBox, Padding

Boxes that wrap other widgets to give them size, color, or breathing room.

child

Container

Color, size, border, padding

A
B

SizedBox

Empty space, fixed size

child

Padding

Push child inward

Built-in Widgets · 3/3

Buttons that do stuff

Three flavors. Pick by how loud you want them to be.

ElevatedButton

Bold, raised, primary action

TextButton

Subtle, secondary

IconButton

Icon-only tap target

Layout · 1/4

Row & Column — the workhorses

90% of layouts are these two. Row = side by side. Column = top to bottom.

Row โ†’ side by side

A
B
C

Column โ†’ stacked

A
B
C
Layout · 2/4

Stack — pile widgets on top

When you want one widget on top of another. Like a badge on an avatar, or text over an image.

Background
Middle
Top

Children render in order. First one at the back. Last one on top. Use Positioned to pin them to corners.

Layout · 3/4

Expanded — "take what's left"

Inside Row or Column, wrap a child in Expanded to fill remaining space.

Without Expanded

A
B
empty space

With Expanded on B

A
B (Expanded)
Layout · 4/4

Alignment — where children sit

mainAxisAlignment = along the row/column. crossAxisAlignment = the other way.

start

A
B

center

A
B

spaceBetween

A
B
Custom Widget · 1/3

Your first widget: StatelessWidget

Make your own widget by extending StatelessWidget and giving it a build(). That's it.

class Greeting extends StatelessWidget {
  Widget build(context) {
    return Text('Hello, friend!');
  }
}

Stateless = once built, it never changes. Perfect for static UI — logos, headers, fixed text.

Custom Widget · 2/3

Make it reusable — pass data in

Add a constructor parameter. Now the same widget can show different text.

class Greeting extends StatelessWidget {
  final String name;
  Greeting(this.name);

  Widget build(c) => Text('Hi, $name');
}

// use it
Greeting('Aayush')
Greeting('Anita')
Custom Widget · 3/3

Compose small → big

Build tiny widgets. Combine them into bigger ones. That's the whole game.

Avatar

+

NameBlock

+

FollowBtn

=

UserCard

3 small widgets = 1 reusable card. Now drop UserCard anywhere in your app.

State · 1/5

Stateless vs Stateful

Two kinds of widgets. The difference: can it change after it's drawn?

๐Ÿ“ท Stateless

A photograph. Once taken, frozen.

โœ“ Logo
โœ“ Header text
โœ“ Profile card (data passed in once)
โœ“ Anything that doesn't change

๐ŸŽฌ Stateful

A video. It plays, changes, updates.

โœ“ Counter (number goes up)
โœ“ Toggle switch
โœ“ Form (user types)
โœ“ Timer / progress bar
State · 2/5

Stateful = widget + state object

Stateful widgets come in two parts. The widget itself + a State class that holds the changing data.

class Counter extends StatefulWidget {
  createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int count = 0; // the changing data
  Widget build(c) => Text('$count');
}
State · 3/5

setState() — "redraw me!"

When data changes, call setState. Flutter redraws the widget with new values.

1. Tap

User clicks button

โ†’

2. setState

You change the data

โ†’

3. Rebuild

build() runs again

โ†’

4. New UI

Screen updates

State · 4/5 · Live demo

The classic counter

Click the button. Watch the number change. That's setState in action.

0

In real Flutter: same thing, but inside setState(() { count++; }).

State · Live demo

Toggle — UI changes shape

Same idea. Different boolean. UI swaps based on state.

๐ŸŒ™
Dark mode is on
State · 5/5 · Gotcha

The #1 beginner mistake

You change the data. UI doesn't update. You wonder why.

โŒ Won't update

count++;
// no setState!

โœ… Updates

setState(() {
  count++;
});

No setState — no rebuild — no UI change. Always wrap state changes in it.

Wireframe · Step 1

From sketch → real UI

A designer hands you this sketch. Your job: turn it into Flutter widgets.

FOLLOW
posts
followers
following
Wireframe · Step 2

Break it into widgets

Look at the sketch. Name each piece. That's your widget tree.

Container (Card)
Row
Column (name+bio)
Button
Row (stats)
142
posts
8.4k
followers
312
following

Container holds Row. Row holds Avatar + Column + Button. Done.

Wireframe · Step 3

Final result

Same widgets. Real colors. Real text. Real Flutter.

Aayush B.
@aayush ยท Kathmandu

Building things on the web. Flutter + Astro.

142
posts
8.4k
followers
312
following

๐ŸŽ‰ You just built UI from a wireframe.

Recap

Today you learned

Bridge

Dart + UI toolkit = Flutter

Project

flutter create, lib/, main.dart

Shell

MaterialApp vs CupertinoApp

Anatomy

Widget tree, build, context

Widgets

Text, Icon, Image, Button

Layouts

Row, Column, Stack, Expanded

Custom

StatelessWidget, params, compose

State

Stateful, setState, dynamic UI

Wireframe

Sketch → widgets → real UI

Homework

Build it yourself.

Practice beats theory. Open DartPad or your editor and ship.

โ˜ Install Flutter SDK
โ˜ flutter create my_first_app
โ˜ Replace counter with your name + button
โ˜ Build the profile card from slide 32
โ˜ Try MaterialApp and CupertinoApp
โ˜ Bonus: counter that goes up by 5
โ˜ Push to flutter-tr06

Day 9: navigation, multiple screens, passing data between pages. See you there.