Created
April 19, 2020 10:08
-
-
Save tanabe1478/009be59d0a0b4ed6261a88e9d3f6f722 to your computer and use it in GitHub Desktop.
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(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: HomePage(), | |
| ); | |
| } | |
| } | |
| class HomePage extends StatefulWidget { | |
| @override | |
| _HomePageState createState() => _HomePageState(); | |
| } | |
| class _HomePageState extends State<HomePage> { | |
| bool _isEnabled = false; | |
| static double _initialWidth = 300; | |
| static double _initialHeight = 300; | |
| double _width = _initialWidth; | |
| double _height = _initialHeight; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('AnimatedContainer'), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| child: Icon(Icons.refresh), | |
| onPressed: () { | |
| changeShape(); | |
| }, | |
| ), | |
| body: Center( | |
| child: AnimatedContainer( | |
| color: Colors.blue, | |
| duration: Duration( | |
| milliseconds: 400, | |
| ), | |
| height: _width, | |
| width: _height, | |
| ), | |
| ), | |
| ); | |
| } | |
| void changeShape() { | |
| setState(() { | |
| _isEnabled = !_isEnabled; | |
| _width = _isEnabled ? 100 : _initialWidth; | |
| _height = _isEnabled ? 100 : _initialHeight; | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment