首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnimatedContainer正在破坏其他动画

AnimatedContainer正在破坏其他动画
EN

Stack Overflow用户
提问于 2020-02-13 10:23:16
回答 1查看 444关注 0票数 1

我是使用动画旋转梯度的同时,当用户按下容器,我想增加容器的大小。

当我使用容器代替按预期工作的AnimatedContainer渐变动画时,当我用AnimatedContainer替换容器时,渐变动画不能正常工作(意思是:在将0旋转到2*math.pi之后,再次重置它,然后启动动画,我希望它继续旋转。)

代码语言:javascript
复制
import 'package:flutter/material.dart';
import 'dart:math' as math;

class Delete extends StatefulWidget {
  Delete({Key key}) : super(key: key);

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

class _DeleteState extends State<Delete> with SingleTickerProviderStateMixin {
  Animation<double> _animation;
  AnimationController _controller;
  double _playButtonSize = 170;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 10));
    _animation = Tween<double>(begin: 0, end: 2 * math.pi).animate(_controller)
      ..addListener(() {
        setState(() {});
      });
    _controller.repeat();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(""),
        ),
        body: Container(
          child: GestureDetector(
            onLongPress: () {
              setState(() {
                _playButtonSize = 185;
              });
            },
            onLongPressEnd: (end) {
              setState(() {
                _playButtonSize = 170;
              });
            },
            child: AnimatedContainer(
                duration: Duration(milliseconds: 100),
                width: _playButtonSize,
                height: _playButtonSize,
                padding: EdgeInsets.all(17.0),
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  gradient: SweepGradient(
                    colors: [
                      Colors.blue,
                      Colors.pink,
                      Colors.orange,
                      Colors.yellow,
                      Colors.blue
                    ],
                    center: Alignment(-0.50, -0.0),
                    endAngle: _animation.value + (2 * math.pi),
                    startAngle: _animation.value,
                    tileMode: TileMode.repeated,
                  ),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.white,
                      blurRadius: 4.0,
                    ),
                  ],
                ),
                child: Icon(
                  Icons.email,
                  size: 50,
                )),
          ),
        ));
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-13 11:10:27

如果您将AnimatedContainer与另一个父Container交换,则您的两个动画都会工作:

代码语言:javascript
复制
return Scaffold(
  appBar: AppBar(
    title: Text(""),
  ),
  body: AnimatedContainer(
    duration: Duration(milliseconds: 100),
    width: _playButtonSize,
    height: _playButtonSize,
    child: GestureDetector(
      onLongPress: () {
        setState(() {
          _playButtonSize = 185;
        });
      },
      onLongPressEnd: (end) {
        setState(() {
          _playButtonSize = 170;
        });
      },
      child: Container(
        padding: EdgeInsets.all(17.0),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          gradient: SweepGradient(
            colors: [
              Colors.blue,
              Colors.pink,
              Colors.orange,
              Colors.yellow,
              Colors.blue
            ],
            center: Alignment(-0.50, -0.0),
            endAngle: _animation.value + (2 * math.pi),
            startAngle: _animation.value,
            tileMode: TileMode.repeated,
          ),
          boxShadow: [
            BoxShadow(
              color: Colors.white,
              blurRadius: 4.0,
            ),
          ],
        ),
        child: Icon(
          Icons.email,
          size: 50,
        )
      ),
    ),
  )
);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60205541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档