Checkpoints
Lab Completion
/ 10
Build a Two Screen Flutter Application
- GSP1010
- Overview
- Task 1. Open the Code Server Editor
- Task 2. Creating a Flutter template
- Task 3. Opening the new app
- Task 4. Running the Flutter web application
- Task 5. Designing the application
- Task 6. Working with ListView
- Task 7. Managing ListView data
- Task 8. Adding interactivity
- Task 9. Creating a details page
- Task 10. Navigating between pages
- Task 11. Passing data between pages
- Congratulations!
GSP1010
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
- Using multiple pages
- Using hot reload for a quicker development cycle
Prerequisites
Based on the content, it is recommended to have some familiarity with:
- Flutter
- Dart
Task 1. Open the Code Server Editor
In this lab, you will use a custom editor that includes the Flutter and Dart extensions. From the initial lab panel:
- Copy the Flutter IDE address displayed
- Paste the IDE address into a Browser tab
Task 2. Creating a Flutter template
In this section, create a Flutter Web application called first_app.
-
Click the hamburger button in the top left () and then click Terminal > New Terminal.
-
In the terminal, enter the following command:
- Move to the first_app directory:
- Close the terminal window:
The first_app
directory and template code have now been created.
Task 3. Opening the new app
In this section, explore the Flutter Web application called first_app.
- Open the folder
first_app
. - Acknowledge the on-screen notifications.
At this point, you will have the Flutter application open in the current workspace.
Task 4. 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 terminal directory is set to
first_app
. - Run the Flutter web server:
- The running web server should look similar to below:
-
Copy the Flutter Live Server address from the lab Panel.
-
Paste the address into a new browser tab.
-
The browser will render the web application e.g.
Feel free to interact with the running application.
Task 5. Designing the application
In this section, use widgets to build a basic two screen application.
From the above sketch, we note that our application uses the following types of widgets.
Widget | Description |
---|---|
AppBar | Header bar |
Scaffold | Screen layout |
Text | Text entry fields |
ListView | Item list |
Task 6. Working with ListView
In this section to build a basic item list, the Flutter page will look similar to the image below:
In the image, there is a list of months presented. A ListView widget is capable of listing items.
To learn more, refer to Lists in the Flutter documentation. In the exercise below, create a basic short list.
- Begin by replacing the template code in
main.dart
with the code below:
-
Save the updated code.
-
Click in the open Terminal window, and press ‘r'.
-
Switch to the
Flutter Device
browser tab. -
Press
CTRL+R
to reload the page.
The code in the above example creates a basic list. Similar to our application sketch, this presents data as outlined in our design.
Task 7. Managing ListView data
In this section, add user interaction to respond when a list item is selected.
Previously, we have looked at using a small amount of data being added to a ListView. Working with larger volumes of data can be challenging. To help with this situation, consider the ListView.builder.
- Declare a List:
- ListView.builder declaration:
In this exercise below, create a long list using a ListView.builder.
- Replace the
MyApp
class with the code below:
-
Click in the open Terminal window, and press ‘r'.
-
Switch to the
Flutter Device
browser tab. -
Press
CTRL+R
to reload the page.
The code in this example creates a long list using the ListView.builder. The page rendered is exactly the same as before. However, this is a better approach to handling larger data sources.
Task 8. Adding interactivity
In this section, add user interaction to respond when a list item is selected. Add interactivity in Flutter typically requires a Gesture Detector. The type of gesture to capture is called a Tap.
Additionally, add a SnackBar to the code so there is a visual notification when a user taps on a list item.
In this exercise, the MyApp
class with the following code:
- Update
MyApp
with the following code:
The implementation of the SnackBar is temporary to provide feedback that our onTap is working correctly.
-
Click in the open Terminal window, and press ‘r'.
-
Switch to the
Flutter Device
browser tab. -
Press
CTRL+R
to reload the page.
Task 9. Creating a details page
In this section, create a second Flutter page and display some more information.
As the second page is very similar to the first page, this can help us construct the code.
- In this exercise, add the following functionality to the
main.dart
file:
At this point, the Details Page
is not connected to the first page.
You'll correct that in the next section.
Task 10. Navigating between pages
In this section, enable navigation between the first page and the second:
Previously, we enabled a SnackBar to indicate that an onTap event had occurred. To achieve navigation will require the following activities:
- Remove the SnackBar code
- Add a navigation between the pages
- Point the navigation to the
MyDetails
class
- Add a Navigator.push to
MyApp
:
-
Click in the open Terminal window, and press ‘r'.
-
Switch to the
Flutter Device
browser tab. -
Press
CTRL+R
to reload the page.
Now, the application will be able to move between the Main page and the Details page. However, the details page always says January. You'll fix that in the next section.
Task 11. Passing data between pages
In this section, learn how to pass information between pages.
- Update the navigation code to pass a parameter:
MyApp
In the code below, use MaterialPageRoute to communicate with your new page. To pass information to the Details page, we use the list item string as a parameter.
- Update
MyApp
to callMyDetails
with a parameter:
MyDetails
Now that MyApp
expects to pass data to the MyDetails
class.
Make the following updates to accept a parameter using a Constructor.
- A Constructor is used to accept the parameter i.e. the list item.
- A variable is used to hold the information passed as a parameter.
- The Text widget is used to display the information passed.
To make the changes, follow the steps below:
- Update
MyDetails
to accept a parameter:
-
Click in the open Terminal window, and press ‘r'.
-
Switch to the
Flutter Device
browser tab. -
Press
CTRL+R
to reload the page:
month
and display it to the user.
Click Check my progress to verify the objective.
Congratulations!
You have successfully completed the lab and demonstrated your knowledge of Flutter. Over the course of this lab, you have performed the following tasks:
- Used a ListView widget
- Refactored code to use ListView.builder
- Added notifications to Flutter using a SnackBar widget
- Declared a new Flutter page
- Passed data between Flutter pages
Manual Last Updated November 15, 2024
Lab Last Tested November 15, 2024
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.