【问题标题】:How to translate with animation如何用动画翻译
【发布时间】:2019-06-19 10:47:32
【问题描述】:

我正在使用 Animator 包来移动容器。我想要实现的是将容器从Alignment.bottomCenter移动到Alignment.topCenter,但我只能使用偏移量。有没有办法使用对齐?

                   Animator(
                          triggerOnInit: _logoMovesUp,
                          tween: Tween<Offset>(
                         //HERE I WANT TO USE THE ALIGNMENT
                              begin: Offset(0.0, 0.0), end: Offset(0.0, -100.0)),
                          duration: Duration(seconds: 1),
                          builder: (anim) => Transform.translate(
                                offset: anim.value,
                                child: Container(
                                    alignment: Alignment.bottomCenter,
                                    child: Container(Text('Test')),
                              ))

【问题讨论】:

    标签: animation flutter translate animator


    【解决方案1】:

    是的,您可以使用 AnimatedAlign。像这样:

    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      Alignment _alignment = Alignment.bottomCenter;
    
      animate() {
        setState(() {
          if (_alignment == Alignment.bottomCenter) {
            _alignment = Alignment.topCenter;
          } else {
            _alignment = Alignment.bottomCenter;
          }
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Animation'),
          ),
          floatingActionButton: FloatingActionButton.extended(
            onPressed: animate,
            label: Text('Animate'),
          ),
          body: Stack(
            children: <Widget>[
              AnimatedAlign(
                alignment: _alignment,
                duration: Duration(milliseconds: 350),
                curve: Curves.easeIn,
                child: Container(
                  color: Colors.orange,
                  child: Text('Test'),
                ),
              ),
            ],
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 2012-04-13
      • 2014-10-03
      • 2013-08-14
      • 2011-09-18
      相关资源
      最近更新 更多