Skip to content

Instantly share code, notes, and snippets.

@legalcodes
Last active November 19, 2019 16:58
Show Gist options
  • Save legalcodes/36bb91f24db7122ec3def0153683edb7 to your computer and use it in GitHub Desktop.
Save legalcodes/36bb91f24db7122ec3def0153683edb7 to your computer and use it in GitHub Desktop.
AnimatedOpacity
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
const owl_url = 'https://raw.githubusercontent.com/flutter/website/master/src/images/owl.jpg';
class FadeInDemo extends StatefulWidget {
_FadeInDemoState createState() => _FadeInDemoState();
}
class _FadeInDemoState extends State<FadeInDemo> {
double opacityLevel = 0.0;
@override
Widget build(BuildContext context) {
return Column(children: <Widget>[
Image.network(owl_url),
MaterialButton(
child: Text(
'Show details',
style: TextStyle(color: Colors.blueAccent),
),
onPressed: () => setState(() {
opacityLevel = 1.0;
}),
),
AnimatedOpacity(
duration: Duration(seconds: 3),
opacity: opacityLevel,
child: Column(
children: <Widget>[
Text('Type: Owl'),
Text('Age: 39'),
Text('Employment: None'),
],
),
)
]);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FadeInDemo(),
),
),
);
}
}
Future<void> main() async {
runApp(MyApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment