我需要为小部件制作动画,并且我使用了AnimatedPositioned。但没有动画。只需更改位置而无需设置动画
完整代码
Column(
children: <Widget>[
Container(
height: 50,
width: width,
color: Palette.white,
child: Padding(
padding: const EdgeInsets.only(left:20.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 200,
height: 40,
decoration: BoxDecoration(
color: Palette.lightSilver,
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Stack(
children: <Widget>[
AnimatedPositioned(
right:check? 0:null,
left:check?null: 0,
child: InkWell(
onTap: (){
setState(() =>
check = !check
);
},
child: Container(
width: 110,
height: 40,
decoration: BoxDecoration(
color: Palette.darkSilver2,
borderRadius: BorderRadius.all(Radius.circular(20))
),
),
),
duration: const Duration(milliseconds: 50000),
curve: Curves.bounceOut,
)
],
),
),
],
),
)
),
您只需要始终从right