我试图解决这个问题,我的ListTile的颜色(1)没有显示在每个tile的背后,而是显示在父容器的溢出部分(2)。
下面是问题的截图:
我正在使用Flutter 2.2.3和Dart 2.13.4版本。 起初我认为是模拟器有问题(Pixel 2 API 30),所以我尝试在Pixel 3 API 30上测试。问题仍然存在。
我请朋友帮忙检查代码是否有问题,他说他找不到任何问题,代码在他的屏幕上运行正常。我不明白为什么会这样,我相信他也只比我用Flutter晚一个版本。使用不同的颜色应用,他的屏幕上看起来像这样,这正是我所期望的。
这让我更难理解问题所在,并且也让我感到困惑,因为他没有更改我的代码,这个问题只在我的屏幕上出现。
如果您需要查看ListView builder和父容器的代码,我将在下面附上它。
这是ListView builder的Widget:
Widget _buildTodoList() {
return ListView.builder(
itemBuilder: (context, i) {
return _buildRow(i + 1, _todoItems[i]);
},
itemCount: _todoItems.length,
);
}
这是 ListTile 的小部件:
Widget _buildRow(int key, String value) {
return Container(
margin: EdgeInsets.only(bottom: 5),
child: ListTile(
// item tile
tileColor: Colors.blueGrey,
leading: Container(
height: 35,
width: 35,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.shade800,
),
child: Center(
child: Text(
key.toString(),
style: TextStyle(
color: Colors.grey.shade300,
),
),
),
),
title: Text(value),
),
);
}
这是父容器:
Expanded(
child: Container(
// for list of items
child: _buildTodoList(),
height: 250,
decoration: BoxDecoration(
color: Colors.blueGrey.shade50,
border: Border.all(
width: 0.6,
color: Colors.black,
style: BorderStyle.solid),
),
),
),
谢谢你!
margin: EdgeInsets.only(bottom: 5),
。你是指列表项底部的颜色还是按钮和其他小部件的背景颜色? - Midhun MP