Animated Opacity
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: "hello",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: const FlutterApp(),
);
}
}
class FlutterApp extends StatefulWidget
{
const FlutterApp({super.key});
@override
State<FlutterApp> createState()
{
return FlutterState();
}
}
class FlutterState extends State<FlutterApp>
{
var myOpacity = 1.0;
bool isVisible = true;
@override
Widget build(BuildContext context)
{
return Scaffold(
drawer: const Drawer(),
appBar: AppBar(
title: const Text("Flutter Animated Opacity",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedOpacity(
duration: const Duration(seconds: 1,),
opacity: myOpacity,
//curve: Curves.slowMiddle,
//curve: Curves.elasticIn,
//curve: Curves.elasticOut,
curve: Curves.bounceInOut,
child: Container(
width: 300,
height: 400,
color: Colors.blue.shade100,
child: const FlutterLogo(size: 200,),
),
),
const SizedBox(height: 70,),
ElevatedButton(
onPressed: (){
setState((){
if(isVisible)
{
myOpacity = 0.0;
isVisible = false;
} else {
myOpacity = 1.0;
isVisible = true;
}
},);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
fixedSize: const Size(350.0,50.0),
),
child: const Text("Close",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0, color: Colors.white),
),
),
],
),
),
),
);
}
}
Comments
Post a Comment