gpt4 book ai didi

list - Flutter 可以创建一个 AnimationController 列表吗?

转载 作者:行者123 更新时间:2023-12-03 04:00:11 25 4
gpt4 key购买 nike

不确定为什么这不起作用,它会抛出错误 RangeError (index): Invalid value: Valid value range is empty: 0

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {

List<AnimationController> dataCtrl = List<AnimationController>();

@override
void initState() {
super.initState();
dataCtrl = [];
dataCtrl[0] = AnimationController(
duration: Duration(milliseconds: 400),
vsync: this,
);
}

最佳答案

@override
void initState() {
super.initState();

// add some AnimationController object before using any index
dataCtrl.add(AnimationController(vsync: this, duration: Duration(seconds: 1)));

// now it is Ok to use 0 index
dataCtrl[0] = AnimationController(
duration: Duration(milliseconds: 400),
vsync: this,
);
}

关于list - Flutter 可以创建一个 AnimationController 列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57874259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com