拥有StatefulWidget,这是一种简单的方法:
var height = 100.0;
var width = 100.0;
@override
void initState() {
super.initState();
_animation();
}
void _animation() {
Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
height = height == 100.0 ? 50.0 : 100.0;
width = width == 100.0 ? 50.0 : 100.0;
});
});
}
@override
Widget build(BuildContext context) {
return Material(
child: Center(
child: AnimatedContainer(
duration: Duration(seconds: 1),
height: height,
width: width,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(50)
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
此代码的结果如下:
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |