我希望使用可滚动的 ListView 和不可移动的标题图块创建一个简单的布局。我已将标题图块和 ListView 放入列中,因此标题可以位于 ListView 上方,而无需滚动到屏幕之外。但是,当滚动 ListView 时,我的标题图块似乎呈现在其“下方”滚动的任何 ListView 图块的颜色。
启动时,该应用程序如下所示:
但是,如果我们向下滚动半个图块,列表图块的绿色似乎会挤出标题中的红色。绿色图块中的文本没有相同的问题,并且被标题图块正确遮挡
重建的最少代码
void main() => runApp(MyTestApp2());
class MyTestApp2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("AppBar Header"),
),
body: Column(children: <Widget>[
ListTile(
title: Center(child: Text("This Header Should be Red")),
tileColor: Colors.redAccent,
),
Expanded(child: ListView(
children: List.generate(20, (int index) => "List Item $index")
.map((n) => ListTile(
title: Text(n.toString()),
tileColor: Colors.lightGreen))
.toList(),
)),
])),
);
}
}
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?我可能可以使用不同的小部件来实现此布局,但我想知道为什么会发生这种颜色溢出效果?它如何适应 Flutter 使用的盒子布局模型? …