Skip to content

Instantly share code, notes, and snippets.

@red-star25
Last active September 24, 2021 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/676b0b1ef7622898fe26eb253a79484f to your computer and use it in GitHub Desktop.
Save red-star25/676b0b1ef7622898fe26eb253a79484f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool showPost = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: const Text("AnimatedCrossFade"),
),
body: Center(
child: AnimatedCrossFade(
crossFadeState:
!showPost ? CrossFadeState.showFirst : CrossFadeState.showSecond,
duration: const Duration(seconds: 1),
firstChild: GestureDetector(
onTap: () {
setState(() {
showPost = true;
});
},
child: Container(
width: 300,
height: 400,
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"Spoiler Alert",
style: TextStyle(fontSize: 18, color: Colors.white),
),
const SizedBox(
height: 20,
),
OutlinedButton(
onPressed: () {
setState(() {
showPost = true;
});
},
child: const Text("Show me"))
],
),
),
),
secondChild: GestureDetector(
onTap: () {
setState(() {
showPost = false;
});
},
child: Container(
width: 300,
height: 400,
color: Colors.blueGrey,
child: Image.network(
"https://memegenerator.net/img/instances/60138700.jpg")),
),
)),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment