Week 5@flutter
Week 5@flutter
EXPERIMENT-5
AIM:
a) Learn about stateful and stateless widgets
CODE:
import 'package:flutter/material.dart';
//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: Color.fromARGB(255, 190, 229, 234),
appBar: AppBar(
leading: const Icon(Icons.menu),
backgroundColor: Colors.blue,
title: const Text(
"Department of IT",
textAlign: TextAlign.start,
),
), // AppBar
body: const Center(
child: Text(
"StateFul Widget",
style: TextStyle(color: Colors.black, fontSize: 30),
),
), // Container
), // Scaffold
); // MaterialApp
}
}
OUTPUT:
Stateless Widget:
CODE:
import 'package:flutter/material.dart';
//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 Color.fromARGB(255, 211, 245, 252),
appBar: AppBar(
leading: const Icon(Icons.menu),
backgroundColor: Colors.blue,
title: const Text(
"Dept of IT",
textAlign: TextAlign.start,
),
), // AppBar
body: const Center(
child: Text(
"Stateless Widget",
style: TextStyle(color: Colors.black, fontSize: 30),
),
), // Container
), // Scaffold
); // MaterialApp
}
}
OUTPUT: