gpt4 book ai didi

Flutter row mainAxisAlignment spaceBetween 不起作用

转载 作者:IT王子 更新时间:2023-10-29 06:51:25 25 4
gpt4 key购买 nike

这是我构建项目 View 容器的代码:

Widget buildItemView(InboxItem t) {

return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("ontap")),
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
icon ...
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[

/// title
_buildTitle(t),

...
],
)
],
)),
Divider(height: 3.0)
],
),
);
}

_buildTitle代码,这里是问题发生的地方:

Widget _buildTitle(InboxItem item) {
return Container(
padding: EdgeInsets.only(bottom: 2.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[

/// sender
Text(item.sender == null ? "" : item.sender, style: ltBlackLargeText),

/// time
Text(item.receiveTime == null ? "" : item.receiveTime,
style: dkGreySmallText),

],
),
);
}

运行结果,时间在用户名后面,而不是右边。

部分截图:

Screenshot

问题出在哪里?

最佳答案

由于上级没有填充剩余空间,更改item查看代码:

Widget buildItemView(InboxItem t) {

return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () => print("ontap")),
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
icon ...
),
Expanded(
child:Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[

/// title
_buildTitle(t),

...
],
) ,
)
],
)),
Divider(height: 3.0)
],
),
);
}

关于Flutter row mainAxisAlignment spaceBetween 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53774849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com