Fade In Fade Out Animation

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: "Fade in Fade out",
debugShowCheckedModeBanner: false,
theme: ThemeData(
// primarySwatch: Colors.grey,
),
home: const FadePractice(),
);
}
}
class FadePractice extends StatefulWidget
{
const FadePractice({super.key});
@override
State<FadePractice> createState()
{
return FadePracticeState();
}
}
class FadePracticeState extends State<FadePractice>
{
bool visible = true;
bool visible2 = true;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fade in Fade out"),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedOpacity(
opacity: visible ? 1.0 : 0.0,
duration: const Duration(seconds: 1),
child: Container(
width: 200.0,
height: 200.0,
color: Colors.green,
),
),
AnimatedOpacity(
opacity: visible2 ? 1.0 : 0.0,
duration: const Duration(seconds: 1),
child: Container(
width: 200.0,
height: 200.0,
child: Image.asset("assets/images/Lord-Hanuman.jpg"),
),
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
onPressed: () {
setState(() {
visible = !visible;
},);
},
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
backgroundColor: Colors.blue,
child: const Icon(Icons.add, color: Colors.white, size: 30.0),
),
const SizedBox(width: 20.0),
FloatingActionButton(
onPressed: () {
setState(() {
visible2 = !visible2;
},);
},
shape: OutlineInputBorder(
borderSide: BorderSide(color: Colors.yellow),
),
backgroundColor: Colors.brown,
child: const Icon(Icons.remove, color: Colors.white, size: 30.0),
),
],
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter