[英]Flutter - Reuse same custom widget class for instances appear not at same time
简而言之,我的问题是如何在父母的setState()
上再次调用孩子的initState()
) 。
我需要为多个实例重用一个小部件 class 。 我需要小部件依次出现,如下所示,我可以使用setState()
在它们之间切换。
bool showthefirstone = true;
@override
Widget build(BuildContext context) {
...
TheWidget it = showthefirstone ? TheWidget(...) : TheWidget(..);
...
}
后者的initState()
没有被调用。 同时将它们显示在一起没有问题。 该问题仅发生在setState()
上。
对于那些不明白的人,这会触发变化
setState((){showthefirstone = !showthefirstone})
这是相同的答案,不同的问题。 我的问题更笼统。 至少适用于我的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.