Animated CrossFade

 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 flutter",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: const FlutterApp(),
);
}
}

class FlutterApp extends StatefulWidget
{
const FlutterApp({super.key});
@override
State<FlutterApp> createState()
{
return FlutterAppState();
}
}

class FlutterAppState extends State<FlutterApp>
{
bool isFirst = true;

@override
void initState()
{
super.initState();

/* Timer(const Duration(seconds: 2,), () {
reload();
},);*/
}

void reload(){
setState((){
if(isFirst){
isFirst = false;
}else {
isFirst = true;
}
});
}

@override
Widget build(BuildContext context)
{
return Scaffold(
drawer: const Drawer(),
appBar: AppBar(
title: const Text("Flutter cross fade"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedCrossFade(
duration: const Duration(seconds: 4,),
firstChild: Container(
/* width: 300,
height: 300,
color: Colors.grey.shade500,*/
child: Image.asset("assets/images/google_icon.png", width: 300, height: 300,),
),

//secondChild: Image.asset("assets/images/flutter.png", width: 300, height: 300,),
secondChild: Image.asset("assets/images/camera-icon-37.png", width: 300, height: 300,),

//sizeCurve: Curves.fastOutSlowIn,
firstCurve: Curves.easeInOut,
secondCurve: Curves.bounceInOut,

//crossFadeState: CrossFadeState.showFirst,
//crossFadeState: CrossFadeState.showSecond,

crossFadeState: isFirst ? CrossFadeState.showFirst : CrossFadeState.showSecond,
),
const SizedBox(height: 80,),

ElevatedButton(
onPressed: (){
setState((){
reload();
},);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
fixedSize: const Size(350.0,50.0),
),
child: const Text("Click Here to Show",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontSize: 20.0),),
),
],
),
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter

Pagination First Practical in Flutter