可容纳一个子组件,并使其进行缩放动画,需要提供动画器scale,拥有alignment属性。

ScaleTransition基本使用

  1. <br />【child】 : 孩子组件 【Widget】<br />【scale】 : 动画 【Animation<double><br />![134.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589456566833-5d28b072-8446-4a44-9f80-2e0428edb4eb.gif#align=left&display=inline&height=242&margin=%5Bobject%20Object%5D&name=134.gif&originHeight=242&originWidth=800&size=187710&status=done&style=none&width=800)
import 'package:flutter/material.dart';
class CustomScaleTransition extends StatefulWidget {
  @override
  _CustomScaleTransitionState createState() => _CustomScaleTransitionState();
}

class _CustomScaleTransitionState extends State<CustomScaleTransition>
    with SingleTickerProviderStateMixin {
  AnimationController _ctrl;

  @override
  void initState() {
    _ctrl = AnimationController(vsync: this, duration: Duration(seconds: 2));
    _ctrl.forward();
    super.initState();
  }

  @override
  void dispose() {
    _ctrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          setState(() {
            _ctrl.reset();
            _ctrl.forward();
          });
        },
        child: Container(
          color: Colors.grey.withAlpha(22),
          width: 100,
          height: 100,
          child: ScaleTransition(
            scale: CurvedAnimation(parent: _ctrl, curve: Curves.linear),
            child: Icon(Icons.android, color: Colors.green, size: 60),
          ),
        ));
  }
}