Flutter - Lab - Manual - With Co-Po Mapping
Flutter - Lab - Manual - With Co-Po Mapping
(Data science)
UI-FLUTTER LAB
III B.TECH -II SEMESTER (CSD)
R22 (MLRS )REGULATION
A.Y: 2024-25
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
(DATA SCIENCE)
CERTIFICATE
This is to certify that this manual is a bonafide record of practical work in the WEB
TECHNOLOGIES in III B. Tech, II semester (CSD) programme during the academic year
2024-25. This book is prepared by Mrs. D. Shushma, Mrs. S. Devi Parvathi, Mrs. Renuka,
department of Computer Science and Engineering (Data science).
This Lab Manual entitled “Web Technologies Lab” is intended for the use of III B. Tech II
Semester Computer Science and Engineering(Data Science) students of Marri Laxman Reddy
Institute of Technology and Management, Dundigal, Hyderabad. The main objective of the Flutter
is Google's UI toolkit for building applications for mobile, web, and desktop from a single
codebase. In this codelab, you will build the following Flutter application: The application generates
cool-sounding names, such as "newstay", "lightstream", "mainbrake", or "graypine".
By
Mrs. D. Shushma
Mrs. Renuka
3
Vision:
Mission:
Programs that integrate global awareness, communication skills and Leadership qualities
4
VISION & MISSION OF DEPARTMENT
Vision:
Mission:
5
Program Educational Objectives
6
PROGRAM OUTCOMES(POs)
Engineering Graduates will be able to:
1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
7
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO2: Programming Skills: Identify required data structures, design suitable algorithms, develop
and maintain software for real world problems
PSO 3: Make use of computational and experimental tools for creating innovative career paths,
to be an entrepreneur and desire for higher studies.
8
R22 B.TECH CSE SYLLABUS
CS506PC: UI DESIGN - FLUTTER
Course Outcomes:
Implements Flutter Widgets and Layouts
Responsive UI Design and with Navigation in Flutter
Create custom widgets for specific UI elements and also Apply styling using themes and
custom styles.
Design a form with various input fields, along with validation and error handling
Fetches data and write code for unit Test for UI components and also animation
TEXT BOOK:
11. 1. Marco L. Napoli, Beginning Flutter: A Hands-on Guide to App Development.
CO-PO-PSO Mapping Matrix:
CO\PO/PSO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1:
Implements
Flutter 3 2 3 - 3 - - 3 - 3
Widgets and
Layouts
CO2:
Responsive
UI Design
3 2 3 - 3 2 - 3 - 3
and
Navigation
in Flutter
CO3: Create
custom
3 2 3 - 3 1 - 3 - 3
widgets and
apply styling
CO4: Design
a form with
validation 2 3 3 2 3 - 2 3 2 3
and error
handling
CO5:
Fetches data,
writes code
3 3 3 3 3 - - 3 3 3
for unit
testing and
animation
PO1 (Engineering knowledge): Demonstrates understanding of Flutter layouts and widgets (3).
PO2 (Problem analysis): Requires analysis of UI layout problems (2).
PO3 (Design/development of solutions): Focuses on designing user interfaces using Flutter widgets (3).
PO5 (Modern tool usage): Uses modern mobile development tools like Flutter (3).
PSO1: Aligns with understanding and designing web/mobile UI elements (3).
PSO3: Promotes modern tools for innovative solutions (3).
CO5: Fetches Data, Writes Code for Unit Testing and Animation
Mapping Levels:
3: Highly related
2: Moderately related
1: Slightly related
-: Not related
This matrix demonstrates how each CO aligns with specific POs and PSOs, ensuring comprehensive coverage of learning
objectives and skill development.
Experiment 1:
1. a) Install Flutter and Dart SDK.
System Requirements
1. Download VS Code:
○ Visit the Visual Studio Code download page and download the installer.
2. Install VS Code:
○ Run the installer and follow the setup wizard to complete the installation.
3. Install Flutter and Dart Plugins:
○ Open VS Code.
○ Go to Extensions (Ctrl+Shift+X).
○ Search for and install the Flutter and Dart extensions.
That's it! You now have Flutter installed and set up on your Windows machine. You can
start building Flutter applications. If you encounter any issues, the flutter doctor
command can provide helpful diagnostics.
import 'package:flutter/material.dart';
void main() {
runApp(Abc());
@override
return MaterialApp(
home: Def(),
);
}
class Def extends StatelessWidget {
const Def({super.key});
@override
return Scaffold(
appBar: AppBar(
title: Text("Welcome"),
backgroundColor: Colors.purple,
),
body: Column(
children: [
//Widgets
],
),);}}
1. What is Dart?
2. What is a Future in Dart?
3. What does the async keyword do in Dart?
4. How do you declare a list in Dart?
5. What is null safety in Dart?
6. What are the key features of the Dart programming language?
7. Explain the difference between var, final, and const in Dart.
8. How does Dart handle asynchronous programming?
9. What are the different types of collections in Dart?
10. What are the data types available in Dart?
11. How do you define a class in Dart?
12. What is the difference between final and const in Dart?
13. What is a constructor in Dart?
14. How do you handle exceptions in Dart?
15. What is Flutter and what are its main components?
16. What is a widget in Flutter?
17. Explain the difference
between StatelessWidget and StatefulWidget.
18. How does the Flutter rendering process work?
19. What is the build method in Flutter?
20. How do you navigate between screens in Flutter?
21. What is a Container widget in Flutter?
22. What is setState in Flutter?
23. What is a Stream in Flutter?
24. How do you add external packages to a Flutter project?
25. What is hot reload in Flutter?
26. How do you handle user input in Flutter?
27. What is the MaterialApp widget?
28. What is a Scaffold widget?
29. What is the purpose of the pubspec.yaml file in a Flutter project?
30. What is MediaQuery used for in Flutter, and how can you use it
to make a widget responsive?
Experiment 2:
2. a) Explore various Flutter widgets (Text, Image, Container, etc.).
Text Widget:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Abc();
);}}
const Abc({super.key});
@override
return Scaffold(
body: Center(
child: Text(
'Hello, Flutter!',
),
),
),}}
Image Widgets
● Network Image
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Abc(),
);
const Abc({super.key});
@override
return Scaffold(
appBar: AppBar(
),
body: Image.network('https://picsum.photos/250?image=9'),
);}}
- assets/abc.jpeg
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
return MaterialApp(
home: Abc(),
);}}
const Abc({super.key});
@override
return Scaffold(
appBar: AppBar(
),
body: Image.asset('assets/abc.jpeg'),
);}}
Container Widget
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Abc(),
);
const Abc({super.key});
@override
return Scaffold(
body: Center(
child: Container(
width: 200,
height: 200,
padding: EdgeInsets.all(16),
margin: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
),
],
),
child: Center(
child: Text(
'Container',
),
),
),
),
);
}
Card Widget
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Abc();
);
const Abc({super.key});
@override
return Scaffold(
body: Center(
child: Card(
shape: RoundedRectangleBorder(
),
child: Container(
width: 300,
height: 150,
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Card Title',
),
SizedBox(height: 10),
Text(
textAlign: TextAlign.center,
),
],
),
),
),
),
);
}
2 b) Implement different layout structures using Row, Column, and Stack
widgets.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: Scaffold(
body: Padding(
child: Column(
children: [
Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
child: Container(
width: double.infinity,
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
),
SizedBox(height: 10),
Stack(
children: [
Container(
width: double.infinity,
height: 150,
decoration: BoxDecoration(
color: Colors.blue[100],
borderRadius: BorderRadius.circular(10),
),
),
Positioned(
top: 20,
left: 20,
child: Text(
'Stacked Text',
Positioned(
bottom: 20,
right: 20,
),
],
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
],),],),),),],),),),);}}
1. How can Flexible and Expanded widgets help in creating responsive layouts?
2. What does the AspectRatio widget do in Flutter?
3. How can MediaQuery be used to adjust font sizes in a responsive design?
4. What is the difference between MediaQuery and LayoutBuilder in handling
responsive layouts?
5. How does the Row widget arrange its children, and when would you use it?
6. What is the main difference between Row and Column widgets in Flutter?
7. How can the Expanded widget be used within a Column to make child
widgets take up available space?
8. What does the Stack widget do, and when would you use it in a layout?
9. How can you control the positioning of children within a Stack?
10.What is the purpose of the Align widget when used inside a Stack?
11.How do Row and Column widgets handle overflow when their content
exceeds available space?
12.How does the Navigator widget manage navigation between screens in
Flutter?
13.What is the difference between named routes and unnamed (anonymous)
routes in Flutter?
14.How do you define and use a named route in a Flutter application?
15.How can you pass data between routes using unnamed routes?
16.What is the role of the RouteSettings class in Flutter's navigation system?
17.What is the purpose of the setState method in Flutter?
18.How does the setState method impact the widget tree?
19.What is the Provider package used for in Flutter?
20.How do you define a ChangeNotifier in Flutter using the Provider package?
21.How do you provide a ChangeNotifier to the widget tree using Provider?
22.How do you access the provided data in a widget using Provider?
23.How do you create a basic custom widget in Flutter?
24.Why would you create custom widgets in a Flutter application?
25.How can you pass data to a custom widget in Flutter?
26.How do you handle user interactions in a custom widget?
27.Can you create custom widgets with state in Flutter? If so, how?
28.What are the benefits of using custom widgets for specific UI elements?
29.What are the advantages of using custom widgets in Flutter for building
complex UIs?
30.How does the null-aware operator (??) work in Dart?
Experiment 3:
3. a) Design a responsive UI that adapts to different screen sizes.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: ResponsiveLayout(),
);
@override
return Scaffold(
body: Column(
children: [
Expanded(
flex: 2,
child: Container(
color: Colors.blue,
child: Center(
child: Text(
'Header',
),
),
),
Expanded(
flex: 8,
child: Row(
children: [
Expanded(
flex: 3,
child: Container(
color: Colors.green,
child: Column(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.green[700],
child: Center(
child: Text(
),
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.green[500],
child: Center(
child: Text(
),
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.green[300],
child: Center(
child: Text(
),
),
),
),
],
),
),
),
Expanded(
flex: 7,
child: Container(
color: Colors.orange,
child: Center(
child: Text(
'Main Content',
),
),
),
),
],
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.red,
child: Center(
child: Text(
'Footer',
),
),
),),],),);}}
3 b) Implement media queries and breakpoints for responsiveness.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: ResponsiveContainer(),
);
@override
double containerWidth;
double containerHeight;
} else {
return Scaffold(
body: Center(
child: Container(
width: containerWidth,
height: containerHeight,
color: Colors.blue,
child: Center(
child: Text(
'Responsive Container',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),),),),),);}}
1. How does the null-aware assignment operator (??=) work in Dart?
2. What does the conditional member access operator (?.) do in Dart?
3. How is the cascade operator (..) used in Dart?
4. What is the purpose of the spread operator (...) in Dart?
5. How does the null-aware spread operator (...?) differ from the spread
operator in Dart?
6. What is the function of the type test operator (is) in Dart?
7. What does the type cast operator (as) do in Dart?
8. How can the ?. operator be useful in Dart when dealing with potentially
null values?
9. What does the ! operator do in Dart when used after a variable?
10. How do you create an empty String list in Dart?
11. How do you use a generic method in Dart?
12. List the built-in types in Dart.
13. How do you import the Dart math library?
14. What is null safety in Dart?
15. What is the build method in Flutter?
16. How do you handle exceptions in Dart?
17. What are the benefits of using the Provider for state
management?
18. How can you implement form validation in Flutter?
19. What are the advantages of responsive design in Flutter
applications?
20. How can you optimize Flutter applications for performance?
21. What is the role of hot restart in Flutter development?
22. How does Flutter’s widget tree architecture contribute to efficient
UI updates?
23. What are the best practices for managing state across different
screens in Flutter?
24. How does the Navigator widget manage navigation between
screens in Flutter?
25. How do you define and use a named route in a Flutter
application?
26. How can you pass data between routes using unnamed routes?
27. How does the setState method impact the widget tree?
28. What is the Provider package used for in Flutter?
29. What does the Stack widget do, and when would you use it in a
layout?
30. What is the purpose of the Align widget when used inside
a Stack?
Experiment 4:
4. a) Set up navigation between different screens using Navigator.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
);
},
),
),
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
),),);}}
4 b) Implement navigation with named routes.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
},
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/details');
},
),
),
);
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
StatelessWidget is used when the part of the UI you are building does not change.
Stateless widgets are immutable, meaning their properties cannot change once they are
created. They are ideal for static content that doesn’t depend on any dynamic data.
StatelessWidget is used when the part of the UI you are building does not change.
Stateless widgets are immutable, meaning their properties cannot change once they are
created. They are ideal for static content that doesn’t depend on any dynamic data.
const Abc({super.key});
@override
Stateful Widgets
StatefulWidget is used when the part of the UI you are building can change dynamically.
Stateful widgets are mutable and can maintain state that changes over time. This is
useful for interactive elements where the appearance or behavior of the widget depends
on user input or other factors.
1. The StatefulWidget class: This is immutable and creates an instance of the State
class.
2. The State class: This is where the mutable state is maintained and updated.
class Abc extends StatefulWidget {
const Abc({super.key});
@override
@override
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: CounterScreen(),
);
@override
void _incrementCounter() {
setState(() {
});
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
),
Text(
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter, // Increment counter when button is pressed
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
5 b) Implement state management using set State and Provider.
State Management Techniques:
● Local State Management: Managing state within a single widget or a small part of
the widget tree.
class CounterScreen extends StatefulWidget {
@override
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
@override
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Count: $_counter'),
● Global State Management: Managing state that needs to be accessed and updated
across multiple widgets or the entire application.
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
int _counter = 0;
void increment() {
_counter++;
void main() {
runApp(
ChangeNotifierProvider(
child: MyApp(),
),
);
@override
return MaterialApp(
home: CounterScreen(),
);
}
class CounterScreen extends StatelessWidget {
@override
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Consumer<CounterModel>(
return Text(
'Count: ${counterModel.counter}',
);
},
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
},
child: Text('Increment'),
),
],
),
),
);
}
To add the provider package to your Flutter project, follow these steps:
Under the dependencies section, add provider along with the version number. As of the
last update, the latest version is 6.0.0, but you should check pub.dev for the latest version.
yaml
Copy code
Dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
To install the new package, run the following command in the terminal
This command will fetch the provider package and add it to your project.
dart
import 'package:provider/provider.dart';
void main() {
runApp(Abc());
const Abc({super.key});
@override
return MaterialApp(
home: Def(),
);
const Def({super.key});
@override
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: () {},
child: Center(
child: Container(
decoration: BoxDecoration(
color: Color(0xff0174d2),
borderRadius: BorderRadius.circular(9),
),
height: 50,
child: Center(
child: Text(
"Get Started",
),),),),),],),);}}
6 b) Apply styling using themes and custom styles.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData.dark(),
home: MyHomePage(),
);
@override
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,),],),),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),);}}
1. How do you create an empty String list in Dart?
2. How do you use a generic method in Dart?
3. List the built-in types in Dart.
4. How do you import the Dart math library?
5. What is null safety in Dart?
6. What is the build method in Flutter?
7. How do you handle exceptions in Dart?
8. What are the benefits of using the Provider for state management?
9. How can you implement form validation in Flutter?
10. What are the advantages of responsive design in Flutter
applications?
11. How can you optimize Flutter applications for performance?
12. What is the role of hot restart in Flutter development?
13. How does Flutter’s widget tree architecture contribute to efficient
UI updates?
14. What are the best practices for managing state across different
screens in Flutter?
15. How does the Navigator widget manage navigation between
screens in Flutter?
16. How do you define and use a named route in a Flutter
application?
17. How can you pass data between routes using unnamed routes?
18. How does the setState method impact the widget tree?
19. What is the Provider package used for in Flutter?
20. What does the Stack widget do, and when would you use it in a
layout?
21. What is the purpose of the Align widget when used inside
a Stack?
22. How do Row and Column widgets handle overflow when their
content exceeds available space?
23. How can you control the positioning of children within a Stack?
24. What are Records in Dart?
25. How do you declare a list in Dart?
26. How can MediaQuery be used to adjust font sizes in a responsive
design?
27. How do you provide a ChangeNotifier to the widget tree
using Provider?
28. What is a Container widget in Flutter?
29. How do you navigate between screens in Flutter?
30. How does the Row widget arrange its children, and when would
you use it?
Experiment 7:
7. a) Design a form with various input fields.
b) Implement form validation and error handling.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: MyForm(),);
}}
@override
@override
return Scaffold(
appBar: AppBar(
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
controller: _nameController,
validator: (value) {
return null;
},
),
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
validator: (value) {
} else if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) {
return null;
},
),
TextFormField(
controller: _passwordController,
obscureText: true,
validator: (value) {
if (value == null || value.isEmpty) {
return null;
},
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
},
child: Text('Submit'),
),],),),),);}}
1. How do Row and Column widgets handle overflow when their content
exceeds available space?
2. How can you control the positioning of children within a Stack?
3. What are Records in Dart?
4. How do you declare a list in Dart?
5. How can MediaQuery be used to adjust font sizes in a responsive
design?
6. How do you provide a ChangeNotifier to the widget tree
using Provider?
7. What is a Container widget in Flutter?
8. How do you navigate between screens in Flutter?
9. How does the Row widget arrange its children, and when would you
use it?
10. How can Flexible and Expanded widgets help in creating
responsive layouts?
11. What is the main difference between Row and Column widgets in
Flutter?
12. How does the null-aware operator (??) work in Dart?
13. How do you create a basic custom widget in Flutter?
14. How can you pass data to a custom widget in Flutter?
15. How do you handle user interactions in a custom widget?
16. Can you create custom widgets with state in Flutter? If so, how?
17. What are the benefits of using custom widgets for specific UI
elements?
18. How can the Expanded widget be used within a Column to make
child widgets take up available space?
19. What does the Stack widget do, and when would you use it in a
layout?
20. How do you create an empty String list in Dart?
21. What are the key features of the Dart programming language?
22. What is the purpose of the pubspec.yaml file in a Flutter project?
23. What is hot reload in Flutter?
24. What is the difference between named routes and unnamed
routes in Flutter?
25. How do you access the provided data in a widget using Provider?
26. How do you define a ChangeNotifier in Flutter using the Provider
package?
27. How do you add external packages to a Flutter project?
28. What is the main difference between Row and Column widgets in
Flutter?
29. What is the Provider package used for in Flutter?
30. What is setState in Flutter?
Experiment 8:
8. a) Add animations to UI elements using Flutter's animation
framework.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: AnimationScreen(),
);
@override
void _toggleVisibility() {
setState(() {
_visible = !_visible;
});
@override
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AnimatedOpacity(
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _toggleVisibility,
),],),),);}}
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: AnimationExamples(),
);
@override
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
)..repeat(reverse: true);
@override
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FadeTransition(
opacity: _fadeAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
),
SizedBox(height: 20),
SlideTransition(
position: _slideAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
SizedBox(height: 20),
ScaleTransition(
scale: _scaleAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.green,),),],),),);}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
Output :
Fade Animation
Slide Animation
Scale Animation
1. What are the key features of the Dart programming language?
2. What is the purpose of the pubspec.yaml file in a Flutter project?
3. What is hot reload in Flutter?
4. What is the difference between named routes and unnamed routes in
Flutter?
5. How do you access the provided data in a widget using Provider?
6. How do you define a ChangeNotifier in Flutter using the Provider
package?
7. How do you add external packages to a Flutter project?
8. What is the main difference between Row and Column widgets in
Flutter?
9. What is the Provider package used for in Flutter?
10. What is setState in Flutter?
11. What is the role of the RouteSettings class in Flutter's navigation
system?
12. How can MediaQuery be used to adjust font sizes in a responsive
design?
13. How does the setState method impact the widget tree?
14. What is the Provider package used for in Flutter?
15. How does Flutter’s widget tree architecture contribute to efficient
UI updates?
16. How do you handle user input in Flutter?
17. What are the benefits of using the Provider for state
management?
18. What are the advantages of responsive design in Flutter
applications?
19. How do you define and use a named route in a Flutter
application?
20. What is a Stream in Flutter?
21. How does Dart handle asynchronous programming?
22. What does the build method do in Flutter?
23. How do you provide a ChangeNotifier to the widget tree
using Provider?
24. What is hot reload in Flutter?
25. How do you handle exceptions in Dart?
26. How do Row and Column widgets handle overflow when their
content exceeds available space?
27. How do you handle user interactions in a custom widget?
28. What is the main difference between Row and Column widgets in
Flutter?
29. What is the build method in Flutter?
30. How can you create custom widgets with state in Flutter?
Experiment 9:
9. a) Fetch data from a REST API.
Note: You have to get the “http” package from “pub.dev” website.
import 'package:http/http.dart' as http;
try {
'x-hasura-admin-secret': adminSecret,
});
if (response.statusCode == 200) {
} else {
// Request failed
} catch (e) {
print('Error: $e'); }
void main() {
fetchBlogs();
}
9 b) Display the fetched data in a meaningful way in the UI.
import 'package:flutter/material.dart';
import 'dart:convert';
void main() {
runApp(MyApp());
@override
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: BlogListScreen(),
);
@override
@override
void initState() {
super.initState();
futureBlogs = fetchBlogs();
@override
return Scaffold(
appBar: AppBar(
title: Text('Blogs'),
),
body: FutureBuilder<List<Blog>>(
future: futureBlogs,
if (snapshot.connectionState == ConnectionState.waiting) {
} else if (snapshot.hasError) {
} else {
return ListView.builder(
itemCount: blogs.length,
return ListTile(
? Image.network(blog.imageUrl!)
: null,
title: Text(blog.title),
subtitle: Text(blog.content),
);
},
);
}
},
),
);
'32qR4KmXOIpsGPQKMqEJHGJS27G5s7HdSKO3gdtQd2kv5e852SiYwWNfxkZOBuQ6';
try {
'x-hasura-admin-secret': adminSecret,
});
if (response.statusCode == 200) {
} else {
} catch (e) {
class Blog {
return Blog(
imageUrl:
);
}
Note : https://subspace.money/blog/whatsub-single-docs-internship-onboarding-docs-
problem-statement-flutter-blog-explorer
1. What is the MaterialApp widget?
2. How do you declare a list in Dart?
3. What are Records in Dart?
4. How do you define a class in Dart?
5. What does the conditional member access operator (?.) do in Dart?
6. How is the cascade operator (..) used in Dart?
7. How do you access the provided data in a widget using Provider?
8. What are the key features of the Dart programming language?
9. What is the difference between final and const in Dart?
10. How do you handle exceptions in Dart?
11. How do you import the Dart math library?
12. How can MediaQuery be used to adjust font sizes in a responsive
design?
13. What is the difference between MediaQuery and LayoutBuilder
in handling responsive layouts?
14. How does the Row widget arrange its children, and when would
you use it?
15. What is the main difference between Row and Column widgets in
Flutter?
16. How can the Expanded widget be used within a Column to make
child widgets take up available space?
17. What does the Stack widget do, and when would you use it in a
layout?
18. How can you control the positioning of children within a Stack?
19. What is the purpose of the Align widget when used inside a
Stack?
20. How do Row and Column widgets handle overflow when their
content exceeds available space?
21. How does the Navigator widget manage navigation between
screens in Flutter?
22. What is the difference between named routes and unnamed
(anonymous) routes in Flutter?
23. How do you define and use a named route in a Flutter
application?
24. How can you pass data between routes using unnamed routes?
25. What is the role of the RouteSettings class in Flutter's navigation
system?
26. What is the purpose of the setState method in Flutter?
27. How does the setState method impact the widget tree?
28. What is the Provider package used for in Flutter?
29. How do you define a ChangeNotifier in Flutter using the Provider
package?
30. What are the benefits of using custom widgets for specific UI
elements?
Experiment 10:
10. a) Write unit tests for UI components.
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
@override
return MaterialApp(
home: MyHomePage(),
);
@override
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
),
Text(
'$_counter',
// style: Theme.of(context).textTheme.headline,
),
],),),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),);}}
testing.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:testing/main.dart';
void main() {
await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
10 b) Use Flutter’s debugging tools to identify and fix issues.
Monitor the debug console for any error messages or logs. Flutter provides detailed error
messages that often include stack traces and helpful tips.
It is used for checking the flow of the Application by passing through classes, and their
functions.
1. What is unit testing?