Animation 设置容器小部件的动画以使屏幕向左

Animation 设置容器小部件的动画以使屏幕向左,animation,flutter,dart,Animation,Flutter,Dart,我想知道如何设置容器小部件的动画,使屏幕向左 我该怎么做 谢谢 这是一种使用SlideTransition实现的方法 class SlideContainerToTheLeft extends StatefulWidget { @override _SlideContainerToTheLeftState createState() => _SlideContainerToTheLeftState(); } class _SlideContainerToTheLeft

我想知道如何设置容器小部件的动画,使屏幕向左

我该怎么做


谢谢

这是一种使用SlideTransition实现的方法

class SlideContainerToTheLeft extends StatefulWidget {
  @override
  _SlideContainerToTheLeftState createState() =>
      _SlideContainerToTheLeftState();
}

class _SlideContainerToTheLeftState extends State<SlideContainerToTheLeft>
    with SingleTickerProviderStateMixin {
  var tween = Tween<Offset>(begin: Offset.zero, end: Offset(-2, 0))
      .chain(CurveTween(curve: Curves.ease));
  AnimationController animationController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 2));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SlideTransition(
          position: animationController.drive(tween),
          child: Container(
            width: 300,
            height: 400,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20), color: Colors.blue),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          animationController.forward();
        },
      ),
    );
  }
}
class SlideContainerToTheLeft扩展StatefulWidget{
@凌驾
_SlideContainerToTheLeftState createState()=>
_SlideContainerToTheLeftState();
}
类_slidecontainertotheletstate扩展状态
使用SingleTickerProviderStateMixin{
变量tween=tween(开始:偏移量.0,结束:偏移量(-2,0))
.chain(曲线之间的曲线(曲线:Curves.ease));
动画控制器;
@凌驾
void initState(){
//TODO:实现initState
super.initState();
动画控制器=
AnimationController(vsync:this,duration:duration(秒数:2));
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
子:幻灯片转换(
位置:animationController.drive(tween),
子:容器(
宽度:300,
身高:400,
装饰:盒子装饰(
边界半径:边界半径。圆形(20),颜色:颜色。蓝色),
),
),
),
浮动操作按钮:浮动操作按钮(
已按下:(){
animationController.forward();
},
),
);
}
}

希望这对您有所帮助。

这是一种使用幻灯片翻译的方法

class SlideContainerToTheLeft extends StatefulWidget {
  @override
  _SlideContainerToTheLeftState createState() =>
      _SlideContainerToTheLeftState();
}

class _SlideContainerToTheLeftState extends State<SlideContainerToTheLeft>
    with SingleTickerProviderStateMixin {
  var tween = Tween<Offset>(begin: Offset.zero, end: Offset(-2, 0))
      .chain(CurveTween(curve: Curves.ease));
  AnimationController animationController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 2));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SlideTransition(
          position: animationController.drive(tween),
          child: Container(
            width: 300,
            height: 400,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20), color: Colors.blue),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          animationController.forward();
        },
      ),
    );
  }
}
class SlideContainerToTheLeft扩展StatefulWidget{
@凌驾
_SlideContainerToTheLeftState createState()=>
_SlideContainerToTheLeftState();
}
类_slidecontainertotheletstate扩展状态
使用SingleTickerProviderStateMixin{
变量tween=tween(开始:偏移量.0,结束:偏移量(-2,0))
.chain(曲线之间的曲线(曲线:Curves.ease));
动画控制器;
@凌驾
void initState(){
//TODO:实现initState
super.initState();
动画控制器=
AnimationController(vsync:this,duration:duration(秒数:2));
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:中(
子:幻灯片转换(
位置:animationController.drive(tween),
子:容器(
宽度:300,
身高:400,
装饰:盒子装饰(
边界半径:边界半径。圆形(20),颜色:颜色。蓝色),
),
),
),
浮动操作按钮:浮动操作按钮(
已按下:(){
animationController.forward();
},
),
);
}
}
希望这对你有帮助