【发布时间】:2020-04-30 08:44:10
【问题描述】:
我有以下容器,并在其中调用一个函数来创建子小部件。子行始终保持居中对齐的问题。我试过两种方法
- alignment: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,
),
),
],
),
),
);
}
这是屏幕截图。
【问题讨论】:
-
你试过
RowWidget的crossAxisAligment属性吗? -
@JoãoSoares 是的,我也尝试过,但还是一样。奇怪的是我尝试了所有选项,但它似乎根本不动。
-
@newbie 如果可能,请分享屏幕截图
-
@CrazyLazyCat 我已根据您的要求添加了屏幕截图?
-
@newbie 是我的回答,你想要达到什么目的?如果是这样,请记住将答案标记为正确,以便其他用户将来可以看到。
标签: flutter alignment containers