Animated opacity

 import "package:flutter/material.dart";


void main() {
runApp(AppShow(),);
}
class AppShow extends StatelessWidget {
AppShow({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Animated Opacity",
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: OpacityDemo(),
);
}
}
class OpacityDemo extends StatefulWidget {
OpacityDemo({super.key});

@override
State<OpacityDemo> createState() {
return AnimatedState();
}
}
class AnimatedState extends State<OpacityDemo> {
var myOpacity = 1.0;
bool isVisible = true;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Animated Opacity"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedOpacity(
opacity: myOpacity,
duration: Duration(seconds: 1,),
curve: Curves.slowMiddle,
child: Container(
width: 300.0,
height: 200.0,
color: Colors.blue,
),
),
SizedBox(height: 30.0,),
ElevatedButton(
onPressed: () {
setState(() {

if(isVisible) {
myOpacity = 0.0;
isVisible = false;
} else {
myOpacity = 1.0;
isVisible = true;
}

},);
},
child: Text("Show Animation"),
),
],
),
),
);
}
}

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