lab3
lab3
Welcome to the Flutter Widgets Lab! In this lab, we'll be exploring the world of
widgets in Flutter and gradually implementing a simple page of a stock market
tracking app. Let's get started!
Prerequisites
Before we begin, make sure you have Flutter and Android Studio installed on your
computer. If you haven't done so already, please refer to the previous lab for
instructions on how to install these tools.
void main() {
runApp(const MyApp());
}
2. replace the `Text` widget in the `appBar` with a `Text` widget that greets the
user:
appBar: AppBar(
title: Text('Welcome to your stock market tracker!'),
),
11. Practice changing the code to generate the output like the following
picture.
Changing Widgets in Response to User Gestures
Now that we've added some basic widgets to our app, let's learn how to change
widgets in response to user gestures. In this section, we'll add a button that shows
detailed analytics of the market when it's tapped.
12.In the `main.dart` file, add a new `StatefulWidget` called `AnalyticsButton`:
class AnalyticsButton extends StatefulWidget {
@override
_AnalyticsButtonState createState() => _AnalyticsButtonState();
}
13. Run your app and you should now see a button that shows detailed
analytics when it's tapped.
Responding to Widget Lifecycle Events
Finally, let's learn how to respond to widget lifecycle events such as initState and
dispose. In this section, we'll add a timer that simulates periodic updates on the
values of the companies.
14. In the `main.dart` file, refactor your code to extract the column of the
companies to a new `StatefulWidget` called `CompanyValues`:
class CompanyValues extends StatefulWidget {
@override
State<CompanyValues> createState() => _CompanyValuesState();
}
15. Run your app and you should now see the values of the companies
updating periodically.
Flutter Layout Widgets Lab
In this lab, you'll practice applying the topics discussed in the presentation on
Flutter Layout Widgets by building a social media app. You'll implement the app in
different steps, applying one of the topics in each step. You'll also learn how to use
Android Studio to debug the layout visually.
Step 1: Create a new Flutter project.
• Open Android Studio and create a new Flutter project.
• Choose a name for your project and select a location to save it.
• Wait for Android Studio to create the project and install the necessary
dependencies.
Step 2: Add a Column widget
• Open the main.dart file.
• Inside the build method of the MyApp class, replace the Text widget with a
Column widget that has three Text widgets as its children.
• The first Text widget should display the string 'Profile Picture' while the
second Text widget should display the string 'Username' and the third Text
widget should display the string 'Bio'.
• Here's an example:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Layout Widgets Lab'),
),
body: Column(
children: <Widget>[
Text('Profile Picture'),
Text('Username'),
Text('Bio'),
],
),
),
);
}
}
• Here's an example:
body: const Column(
children: <Widget>[
Text('Profile Picture'),
Text('Username'),
Text('Bio'),
Row(
children: <Widget>[
Text('Followers'),
Text('Following'),
Text('Posts'),
],
),
],
),