Last active
March 28, 2022 18:52
-
-
Save jescacena/edeb7da4e3c9492054e2e6d74bd7464e to your computer and use it in GitHub Desktop.
Flutter AnimatedOpacity Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const owlUrl = | |
'https://raw.githubusercontent.com/flutter/website/master/src/images/owl.jpg'; | |
class FadeInDemo extends StatefulWidget { | |
const FadeInDemo({Key? key}) : super(key: key); | |
@override | |
_FadeInDemoState createState() => _FadeInDemoState(); | |
} | |
class _FadeInDemoState extends State<FadeInDemo> { | |
double opacity = 0.0; | |
@override | |
Widget build(BuildContext context) { | |
return Column(children: <Widget>[ | |
Image.network(owlUrl), | |
TextButton( | |
child: const Text( | |
'Show Details', | |
style: TextStyle(color: Colors.blueAccent), | |
), | |
onPressed: () => setState(() { | |
opacity = 1; | |
}), | |
), | |
AnimatedOpacity( | |
duration: const Duration(seconds: 2), | |
opacity: opacity, | |
child: Column( | |
children: const [ | |
Text('Type: Owl'), | |
Text('Age: 39'), | |
Text('Employment: None'), | |
], | |
), | |
) | |
]); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: FadeInDemo(), | |
), | |
), | |
); | |
} | |
} | |
void main() { | |
runApp( | |
const MyApp(), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment