flutter - 即使使用对齐方式或列元素无法更改行左对齐,颤动的行元素仍保持居中?
问题描述
我有以下容器,并在其中调用一个函数来创建子小部件。子行始终保持居中对齐的问题。我试过两种方法
- 对齐:Alignment.topLeft,
- 我尝试将其进一步嵌入列中并尝试使用 crossAxisAlignment:CrossAxisAlignment.start。
两种方法都无法将元素左对齐。它将残留物保留在容器的中心部分。下面可能有问题的是我的代码。
Container(
alignment:Alignment.topRight,
margin: const EdgeInsets.fromLTRB(10, 10, 0, 0),
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
buildDateTime("datetime"),
]
)
],
)
),
下面是我调用来构建行的小部件。
Widget buildDateTime(String plate) {
return new Container(
child: Container(
color: Colors.transparent,
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Icon(Icons.access_time, size: 15.0, color: lightGrey),
Text(
' 23/01/20202',
style: new TextStyle(
color: lightGrey,
fontFamily: "Bpreplay",
fontWeight: FontWeight.w400,
fontSize: 14.0,
),
),
Text(
' 09:00',
style: new TextStyle(
color: lightGrey,
fontFamily: "Bpreplay",
fontWeight: FontWeight.w400,
fontSize: 14.0,
),
),
],
),
),
);
}
这是屏幕截图。
解决方案
我无法重现您提到的问题。对我来说,它占据了整个宽度。
尝试这个,
Widget buildDateTime(String plate) {
return Align(
alignment: Alignment.centerLeft,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(Icons.access_time, size: 15.0, color: Colors.grey),
Text(
' 23/01/20202',
style: const TextStyle(
color: Colors.grey,
fontFamily: "Bpreplay",
fontWeight: FontWeight.w400,
fontSize: 14.0,
),
),
Text(
' 09:00',
style: const TextStyle(
color: Colors.grey,
fontFamily: "Bpreplay",
fontWeight: FontWeight.w400,
fontSize: 14.0,
),
),
],
),
);
}
推荐阅读
- github - 我如何知道在 github 操作中运行工作流的总时间?
- python - 如何对 JSON 进行排序?
- docker - 无法使用云构建上传非图像工件
- elasticsearch - Kibana 管理中未显示索引模式
- c - 八进制转二进制的程序
- pandas - pandas同属性比较
- akamai - Akamai Media Services Live Api:限制流查询的结果
- visual-c++ - lambda:使用已删除的赋值运算符捕获“this”会发出编译器警告
- r - 是否可以将 RMarkdown 块放在 Rmd 文件的表格单元格中?
- c++ - 如何转换多次调用自身的递归算法?