【发布时间】:2020-08-01 01:01:23
【问题描述】:
类 SecondScreen 扩展 StatefulWidget { int myIndexValue;
SecondScreen(this.myIndexValue);
@覆盖
_SecondScreenState createState() => _SecondScreenState();
}
class _MusicPlayingState extends State<MusicPlaying> {
@override
void initState() {
super.initState();
setState({
widget.myIndexValue = widget.myIndexValue + 1;
});
}
@override
Widget build(BuildContext context) {
return Text(widget.myIndexValue.toString());
}
}
编辑:我找到了答案。在到处放置打印语句之后。我发现经常调用状态小部件的构建功能。所以我把一个setstate放在一个函数里,放在build方法下。
【问题讨论】:
-
请详细说明您要达到的目标。
-
我正在尝试将 widget.myIndexValue 更改为任意数字。
-
@hellobear 你不能修改
widget.X因为它是最终的,你必须按照我在回答中提到的方式进行。 -
想把你的编辑变成其他人的正确答案。
标签: flutter