Skip to content

Instantly share code, notes, and snippets.

@funwithflutter
Created August 10, 2021 20:24
Show Gist options
  • Save funwithflutter/5d22cc05f452871c910d9ff006f6c03f to your computer and use it in GitHub Desktop.
Save funwithflutter/5d22cc05f452871c910d9ff006f6c03f to your computer and use it in GitHub Desktop.

Revisions

  1. funwithflutter created this gist Aug 10, 2021.
    58 changes: 58 additions & 0 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    import 'package:flutter/material.dart';

    void main() => runApp(const MyApp());

    class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);

    @override
    Widget build(BuildContext context) {
    return const MaterialApp(
    title: 'Implicit Animation Example',
    home: Scaffold(
    body: Center(
    child: Example(),
    ),
    ),
    );
    }
    }

    class Example extends StatefulWidget {
    const Example({Key? key}) : super(key: key);

    @override
    _ExampleState createState() => _ExampleState();
    }

    class _ExampleState extends State<Example> {
    static const double _startWidth = 100.0;
    static const double _startHeight = 100.0;
    static const Color _startColor = Colors.red;

    double width = _startWidth;
    double height = _startHeight;
    Color color = _startColor;

    void _animateContainer() {
    setState(() {
    width = (width == _startWidth) ? _startWidth * 2 : _startWidth;
    height = (height == _startHeight) ? _startHeight * 2 : _startHeight;
    color = (color == _startColor) ? Colors.blue : _startColor;
    });
    }

    @override
    Widget build(BuildContext context) {
    return GestureDetector(
    onTap: _animateContainer,
    child: AnimatedContainer(
    duration: const Duration(milliseconds: 600), // Play around with the duration of the animation
    curve: Curves.linear,
    width: width,
    height: height,
    color: color,
    ),
    );
    }
    }