Table of Contents
Overview
Flutter is Google's UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
In this lab, you will create a Flutter app using generated template code. The basic Flutter interface provides a simple example to get started programming in Flutter.
What you'll learn
How to write a Flutter app that looks natural on iOS, Android, and the web
Basic structure of a Flutter app
Finding and using packages to extend functionality
Using hot reload for a quicker development cycle
Prerequisites
Based on the content, it is recommended to have some familiarity with:
Flutter
Dart
Setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
- Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
Task 1. Open the Code Server editor
In this lab, we will use a custom editor that includes the Flutter and Dart extensions. From the initial Qwiklabs panel:
Copy the IDE value displayed.
Paste the IDE value into the a new browser window.
Note:
Code Server Editor:
Based on VS Code
Supports Extensions
Task 2. Flutter extensions
Flutter extensions have been installed within the editor.
In the editor select the extensions icon:
Note:
Flutter extension provides support for developing with the Flutter Framework
Dart language extension will automatically be installed as part of the Flutter extension
Task 3. Create a Flutter template
Note: The Flutter Framework enables the creation of multi-platform applications e.g. Android, iOS, Windows and Web.
In this section create a Flutter Web application called startup_namer.
Click the navigation menu button (i.e. left hand side, three horizontal lines).
Open a Terminal within the browser by selecting New Terminal:
- In the terminal enter the following command:
flutter create startup_namer
Note:
Flutter Create:
Generates a sample application based on a template.
Provides support for different platforms (e.g. Android, iOS and Web)
Hierarchy includes all the files required for a basic Flutter application
- Move to the startup namer directory:
cd startup_namer
- Close the terminal window:
exit
The startup_namer
directory and template code have now been created.
Task 4. Exploring the Flutter code
In this section edit the Flutter Web application. Use the editor to open the startup_namer
directory created in the previous step.
Note: The editor will make helpful suggestions in relation to the extensions selected. These suggestions should be accepted.
From the main panel select the
Explorer
Icon:Select the
Open Folder
option.Open the
startup_namer
folder:
/home/ide-dev/startup_namer/
- The editor view will change to the Folder view.
- Explore the template code, especially the
lib/main.dart
andpubspec.yaml
files.
At this point it is worth pointing out some information about the editor:
Note:
Code Server:
Generates a sample application based on a template.
Provides support for different platforms (e.g. Android, iOS and Web)
Hierarchy includes all the files required for a basic Flutter application
The lab focuses on building a Web application
Task 5. Running the Flutter Web application
In this section run the Flutter Web application from the command line.
In the editor, open a terminal.
Ensure the directory is set to
startup_namer
.
Note:
Flutter Web:
Uses a web server
Application will be run in the browser
Application will bind to the machine IP/PORT
- Run the Flutter web server:
fwr
- The running web server should look similar to below:
Copy the
Live Server
from the Qwiklabs panel.Paste the address into a new browser tab.
The browser will render the web application:
Feel free to interact with the running application.
Task 6. Flutter Hot reload
Flutter supports Hot reload
which means changes can be made to the application dynamically.
Note:
Hot Reload:
Support for different platforms (e.g. Android, iOS and Web)
Watch the YouTube video Hot reload?! | Decoding Flutter
In this section we use the Hot reload
function to change the Title.
In the editor, amend the file
lib/main.dart
.Look for
class MyApp
and find the Title fieldFlutter Demo Home Page
.
- Amend the HomePage
title
value online 34
to the following:
Flutter is awesome!
Save the editor changes made i.e.
CTRL+S
.The
lib/main.dart
code should now look similar to below:
- Click in the open Terminal window, and press r:
Switch to the
Live Server
browser tab.Press
CTRL+R
to reload the page.
Awesome work getting started with Flutter.
Click Check my progress to verify the objective.
Assess my progress
Solution of Lab