假设我的 PageView
中有 4 个 child
PageView(
children: <Widget>[
Page1(),
Page2(),
Page3(), // how to skip this when a condition is false
Page4(),
],
)
我想在 bool
值为 true
时显示 Page3
,我该怎么做,我想放一个 null
但我不允许这样做。
最佳答案
一种方法是使用 - 使用 sync*
函数。
condition
为真,Page2
将被显示。
bool condition = true;
PageView(
children: List.unmodifiable(() sync* {
yield Center(child: Text('Page1')); //Page 1
if (condition) {
yield Center(child: Text('Page2')); // Page2(conditional)
}
// yield* children;
yield Center(child: Text('Page3')); //Page3
}()),
),
关于dart - Flutter 在 ListView 或 PageView 中跳过 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54842549/