Last active
April 8, 2021 13:56
-
-
Save guid-empty/e8b6f069704715c7662cb8b52f8874cc to your computer and use it in GitHub Desktop.
Implicit Animations - AnimatedCrossFade
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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class OtusLogo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Image.network('https://github.com/flutter-cats/otus-cocktails-application/blob/master/logo-2.8602b.svg'), | |
width: 200.0, | |
height: 200.0, | |
); | |
} | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
bool _showFirstChild = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Implicit Animations - AnimatedCrossFade'), | |
), | |
body: Center( | |
child: AnimatedCrossFade( | |
duration: const Duration(seconds: 1), | |
firstChild: const FlutterLogo( | |
style: FlutterLogoStyle.horizontal, size: 200.0), | |
secondChild: OtusLogo(), | |
crossFadeState: _showFirstChild | |
? CrossFadeState.showFirst | |
: CrossFadeState.showSecond, | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_showFirstChild = !_showFirstChild; | |
}); | |
}, | |
child: _showFirstChild | |
? Icon(Icons.last_page) | |
: Icon(Icons.first_page), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment