Skip to content

Instantly share code, notes, and snippets.

@tanabe1478
Created April 19, 2020 10:08
Show Gist options
  • Select an option

  • Save tanabe1478/009be59d0a0b4ed6261a88e9d3f6f722 to your computer and use it in GitHub Desktop.

Select an option

Save tanabe1478/009be59d0a0b4ed6261a88e9d3f6f722 to your computer and use it in GitHub Desktop.
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