【发布时间】:2021-06-11 18:29:24
【问题描述】:
【问题讨论】:
-
尝试使用 RichText 来连接多个文本小部件。
-
@Sahdeep Singh 我已经试过了,那是行不通的。如果下一个文本小部件对于一行来说太长,Flutter 会自动换行
标签: flutter flutter-layout flutter-animation
【问题讨论】:
标签: flutter flutter-layout flutter-animation
你可以使用ListTile它自带各种参数
例如:根据您的截图示例代码将是
ListTile(
leading: CircleAvatar(
backgroundImage: CachedNetworkImageProvider(userDisplayImage),
//userDisplayImage would be URL
),
title: Text(chatMessage),//Your Chat Message
trailing: Icon(Icons.more_vert),
//If you want to add functionality (eg. option) you can simply replace with
trailin: IconButton(
onPressed: () => print("Option"),//Add functionality
icon: Icon(Icons.more_vert),
),
);
希望这能解决您的问题
【讨论】:
您可以使用RichText 小部件
Container(
padding: EdgeInsets.all(10),
width: 200,
color: Colors.black,
child: RichText(
text: TextSpan(
text: 'aaaaaa',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
children: <TextSpan>[
TextSpan(
text: ' bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.normal,
),
)
],
),
),
)
显然,您可以使用两个变量将两个字符串传递给两个 TextSpan 小部件。
这是你得到的输出
【讨论】: