• Source
    1. import 'package:flutter/material.dart';
    2.  
    3. class AnimatedContainerPage extends StatefulWidget {
    4. @override
    5. State<StatefulWidget> createState() => AnimatedContainerState();
    6. }
    7.  
    8. class AnimatedContainerState extends State<AnimatedContainerPage> {
    9. bool selected = false;
    10.  
    11. @override
    12. Widget build(BuildContext context) {
    13. return Scaffold(
    14. appBar: new AppBar(
    15. title: Text('AnimatedContainer'),
    16. ),
    17. body: GestureDetector(
    18. onTap: () {
    19. setState(() {
    20. selected = !selected;
    21. });
    22. },
    23. child: Center(
    24. child: AnimatedContainer(
    25. width: selected ? 200.0 : 100.0,
    26. height: selected ? 100.0 : 200.0,
    27. color: selected ? Colors.red : Colors.blue,
    28. alignment:
    29. selected ? Alignment.center : AlignmentDirectional.topCenter,
    30. duration: Duration(seconds: 2),
    31. curve: Curves.fastOutSlowIn,
    32. child: FlutterLogo(size: 75),
    33. ),
    34. ),
    35. ),
    36. );
    37. }
    38. }
    39.