Last active
April 8, 2021 13:56
-
-
Save guid-empty/9ce03f678de3290f8e4d0bcb35974d97 to your computer and use it in GitHub Desktop.
Implicit Animations - AnimatedContainer
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 _checked = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Implicit Animations - AnimatedContainer'), | |
), | |
body: Center( | |
child: AnimatedContainer( | |
width: _checked ? 400.0 : 200.0, | |
height: _checked ? 400.0 : 200.0, | |
color: _checked ? Colors.red : Colors.green, | |
duration: const Duration(seconds: 1), | |
child: OtusLogo(), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_checked = !_checked; | |
}); | |
}, | |
child: _checked ? Icon(Icons.check_box_outline_blank) : Icon(Icons.check_box), | |
), // 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