Learning Outcomes / Goals
● How to create a new Flutter app
● Basic structure of a Flutter app
● Using hot reload for a quicker development cycle
Exercise 1
In this exercise, you will create your first Flutter app
Steps for Creating and Running Flutter Application
1. Invoke V
iew > Command Palette.
2. Type “flutter”, and select the Flutter: New Application Project.
3. Enter a project name, such as myapp
, and press Enter.
4. Create or select the parent directory for the new project folder.
5. Wait for project creation to complete and the m
ain.dartfile to appear.
6. Locate the VS Code status bar (the blue bar at the bottom of the window):
7. Select a device from the Device Selector area
8. Invoke R
un > Start Debugging or press F
5
.
After the app build completes, you’ll see the starter app on your
device.
Try hot reload
Flutter offers a fast development cycle with Stateful Hot Reload, the ability to reload
the code of a live running app without restarting or losing app stat
1. Open lib/main.dart.
2. Change the string
'You have p
ushedthe button this many times'
to
'You have c
lickedthe button this many times'
3. Save your changes: invoke Save All, or click Hot Reload
.You’ll see the updated string in the running app almost immediately.
Exercise 2
In this exercise, you will create a simple “Hello World” Flutter app
1. Delete all of the code from lib/main.dart
2. Replace it with the following code, which displays "Hello World" in the center of the
screen
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: const Text('Hello World'),
),
),
);
}
}
Run the app. You should see the following on your device
.