Created
November 6, 2019 12:17
-
-
Save iapicca/8b557eebb34e8c03a98db03dd9d118ac to your computer and use it in GitHub Desktop.
AnimatedContainer
This file contains hidden or 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(MaterialApp(home: MyApp())); | |
| class MyApp extends StatefulWidget { | |
| @override | |
| _MyAppState createState() => _MyAppState(); | |
| } | |
| class _MyAppState extends State<MyApp>{ | |
| static const Duration _duration = Duration(seconds: 1); | |
| bool _state = true; | |
| double _width = 2.0; | |
| Color _color = Colors.red; | |
| void _play() => setState((){ | |
| _state=!_state; | |
| _color= _state?Colors.red:Colors.blue; | |
| _width = _state?2.0:20.0; | |
| }); | |
| @override | |
| Widget build(BuildContext context)=> Scaffold( | |
| body: GestureDetector( | |
| onTap:()=> _play(), | |
| child: Padding( | |
| padding: EdgeInsets.all(40), | |
| child: Stack( | |
| children: <Widget>[ | |
| Align( | |
| alignment: Alignment.centerRight, | |
| child:AnimatedContainer( | |
| width: 80, | |
| height: 80, | |
| duration: _duration, | |
| color: _color, | |
| ),), | |
| Align( | |
| alignment: Alignment.centerLeft, | |
| child:AnimatedContainer( | |
| width: 80, | |
| height: 80, | |
| duration: _duration, | |
| decoration: BoxDecoration( | |
| color: _color, | |
| border: Border.all( | |
| color: Colors.black, | |
| width: _width, | |
| ),),),), | |
| ], | |
| ),),),); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment