DEPARTMENT OF INFORMATION TECHNOLOGY
EXPERIMENT-5
AIM:
a) Learn about stateful and stateless widgets
CODE:
import 'package:flutter/[Link]';
//This function triggers the build process
void main() => runApp(const MyApp());
// StatefulWidget
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
// ignore: library_private_types_in_public_api
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: [Link](255, 190, 229, 234),
appBar: AppBar(
leading: const Icon([Link]),
backgroundColor: [Link],
title: const Text(
"Department of IT",
textAlign: [Link],
),
), // AppBar
body: const Center(
child: Text(
"StateFul Widget",
style: TextStyle(color: [Link], fontSize: 30),
),
), // Container
), // Scaffold
); // MaterialApp
}
}
OUTPUT:
Leave space for to draw the output
Stateless Widget:
CODE:
import 'package:flutter/[Link]';
//This function triggers the build process
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: const [Link](255, 211, 245, 252),
appBar: AppBar(
leading: const Icon([Link]),
backgroundColor: [Link],
title: const Text(
"Dept of IT",
textAlign: [Link],
),
), // AppBar
body: const Center(
child: Text(
"Stateless Widget",
style: TextStyle(color: [Link], fontSize: 30),
),
), // Container
), // Scaffold
); // MaterialApp
}
}
OUTPUT:
Leave space for to draw the output
b) Implement state management using set State and Provider.