03 Flutter Getting-Started
03 Flutter Getting-Started
with Flutter
Jumail Bin Taliba
School of Computing, UTM
March 2020
• Creating Flutter Projects
• Flutter Project Structure
Outline • Building UI by example
• From VS Code
Several ways of • Using Flutter tool from
Command Line (Git Bash, Cmd
creating Flutter or Powershell)
projects • Clone from an existing project
Creating Flutter Project from VS Code
1. In VS Code, open Command Palette, Ctrl Shift P
2. Choose from the menu, Flutter New Project
Creating Flutter Project with CLI
1. Open Git Bash
2. Move to the directory where you save all your flutter projects.
cd d:/code/flutter
5. Run flutter tool to start creating the project (don’t forget the dot)
flutter create .
6. Open the source code into VS Code (don’t forget the dot)
code .
Creating Flutter Project by cloning
1. Copy the folder of any of your existing project.
• You can clone from git file (created with git bundle), or from online repo (e.g. github)
• You can copy from a zip file, or a folder
In the following example, we are going to copy / clone from my project template
on github.
5. Open the source code into VS Code (don’t forget the dot)
code .
Flutter Project Structure
to download dependencies
Basic Flutter Program
For Convenience
• Install VS Code extensions
• Flutter
• Enable: UI guides
• Bracket Pair Colorizer
• Pub spec Assist
4. Go to the starting point of the project and create a new branch to start
editing
git checkout b35b0b8 –b playground
5. Open the source code into VS Code (don’t forget the dot)
code .
appBar
body
floatingActionButton
bottomNavigationBar
Scaffold Components (1)
drawer endDrawer
AppBar Components
bottom
Adding AppBar
Adding TabBar
Code 1
Code 2
Single code refactor
Code 3
Code 4
• Refactor to constants
• Refactor to methods and
How to functions
Refactoring • Refactor to classes
• Further refactoring: files and
directories
How to Refactoring (1)
Before refactoring
Refactor to constant
Delegate widget creation
to variables
After refactoring
In VS Code:
Extract Local Variable
How to Refactoring (2)
After refactoring
Refactor to method
Split code within the class
In VS Code:
Extract Method
How to Refactoring (3)
After
refactoring
Refactor to function
Split code to outside of class
In VS Code:
Extract Method
How to Refactoring (4)
After
refactoring
Refactor to class
Split code to different classes.
It iRecommended approach
In VS Code:
Extract Widget
How to Refactoring (5)
• Further refactoring to separate files
• It is a good practice to use dedicated files and directory structure
• Easy to maintain
• Easy to scale
• Better for teamwork
• Example project
directory structure:
Refactoring Our Code (1)
After
refactoring
Here, we are using
Refactoring to functions
Refactoring Our Code (2)
Refactoring AppBar
Refactoring Our Code (3)
title
leading trailing
subtitle
Adding ListTile
• Wrapped with Container
widget and specify decoration
• Wrapped width Card widgets
Several ways to • ListTile.divideTiles()
add separators • ListView.separated (….)
Adding Separator – Approach 1, wrapped with Container
Decorate the bottom border of the container from
the attribute decoration
Adding Separator – Approach 2, wrapped with Card
Adding Separator – Approach 3, ListTile.divideTiles()