【发布时间】:2020-04-13 01:19:23
【问题描述】:
我想将 listview 的子视图对齐在与中右对齐的同一级别,我使用以下代码:
body: Container(
child: ReorderableListView(
onReorder: (oldIndex, newIndex) {
setState(() {
_updateItems(oldIndex, newIndex);
});
},
children: [
for (final item in data)
Card(
key: ValueKey(item),
color: Colors.grey,
child: Container(
padding: const EdgeInsets.only(left: 10, right: 10),
child: CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: true,
onChanged: (bool value) {
setState(() {
value = !value;
});
},
title: Align(
alignment: Alignment.centerRight,
child: Text(
'$item',
style: TextStyle(
color: Colors.white,
),
),
),
),
),
),
],
),
),
但结果是这个图像:
您可以看到有些孩子比其他孩子有更多的空间,如何解决这个问题,请帮助我,谢谢。
【问题讨论】:
-
您能提供您正在使用的数据吗?看来问题出在数据上,尝试使用 trim 方法如下:
title: Align( alignment: Alignment.centerRight, child: Text( '${item.toString().trim()}', style: TextStyle( color: Colors.white, ), ), )