【发布时间】:2019-11-03 12:39:06
【问题描述】:
我试图使用 ListTile 在左侧显示一个小标题,然后在尾部小部件中显示一个较长的文本。如果没有足够的水平空间,我的想法是让尾随文本分成多行。
我还尝试使用以下代码创建自己的图块:
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 12),
child: Text(
"Campus",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
),
),
),
Text(
"20h course - New students -",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
),
),
],
),
),
在 Pixel 2 XL 模拟器中使用此代码,因为有足够的空间,所以一切都与预期的一样:
但是当我在 Nexus One 模拟器中尝试它时,由于它的大小,这里是输出:
为了让文字分成多行,我把右边的文字包裹成一个灵活的小部件:
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 12),
child: Text(
"Campus",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
),
),
),
Flexible(
child: Text(
"20h course - New students -",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
但问题是,即使文本被分成两行,它使用的空间也比需要的多,所以还有空白空间:
我也尝试使用对齐小部件将文本移动到末尾,但也没有运气。有什么想法吗?
【问题讨论】: