StatefulWidget LifeCycle Example

 import "package:flutter/material.dart";


void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "StatefulWidget LifeCycle",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const StatefulWidgetLifeCycle(),
);
}
}
class StatefulWidgetLifeCycle extends StatefulWidget
{
const StatefulWidgetLifeCycle({super.key});
@override
State<StatefulWidgetLifeCycle> createState()
{
return StatefulWidgetLifeCycleState();
}
}
class StatefulWidgetLifeCycleState extends State<StatefulWidgetLifeCycle>
{
final Color _containerColor = Colors.yellow;

void changeColor()
{
setState(() {
if(_containerColor == Colors.yellow)
{
_containerColor == Colors.red;
return;
}
_containerColor == Colors.yellow;
},);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("StatefulWidget LifeCycle Example"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Container(
decoration: BoxDecoration(
color: _containerColor,
),
),
floatingActionButton: FloatingActionButton(
onPressed: changeColor,
child: const Icon(Icons.add),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter