flutter - 在行左对齐中颤动显示小部件
问题描述
我在一行中有 2 个小部件,并在 mainaxisalignment 中使用 SpaceBetween。问题是我需要在左侧显示第二个小部件
我的代码
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'ID : ',
style: new TextStyle(
fontSize: 11,
fontFamily: 'PoppinsBold')),
new TextSpan(
text: ' ${widget.patientDetails['mrn']}',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Age : ',
style: new TextStyle(
fontSize: 11,
fontFamily: 'PoppinsBold')),
new TextSpan(
text: '${widget.patientDetails['age']}',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
)
])
我面临的问题是这个
我需要使用 spaceBetween must 因为如果我的数据长度增加,它会自动出现在左侧。但如果长度较短,我需要在左侧显示
解决方案
只需将 RichText 包装在一个屏幕大小为一半的容器内
Row(
children: [
Container(width: MediaQuery.of(context).size.width/2,
padding:const EdgeInsets.only(left: 10),
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
TextSpan(
text: 'ID : ',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsBold')),
TextSpan(
text: 'mrn0987654234567',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
),
Container(width: MediaQuery.of(context).size.width/2,
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: 10),
child: RichText(
text: TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
TextSpan(
text: 'Age : ',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsBold')),
TextSpan(
text: 'age124567898765',
style: TextStyle(
fontSize: 11,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
),
)
]),
推荐阅读
- c# - 通过控制器注入时,作用域生命周期服务变为单例
- postgresql - 错误:“文本”位置或附近的语法错误:314
- c# - DirectX (SharpDX) 线框错误
- spring-boot - Spring/Java Mail:发件人始终是 spring.mail.username。FROM 地址被忽略
- javascript - 填补空档
- python - 按组将值替换为python中两个先前值的总和
- node.js - 如何终止由childProcess.exec创建的子进程创建的进程?
- javascript - 如何使用 Leaflet 的脉冲图标动态切换颜色
- multithreading - 多线程 PySpark,无法序列化对象异常
- javascript - React - 如何使用 handleInputChange 函数来更改状态值内的状态值?