颤抖的文字小部件
我正在使用此代码来创建显示用户的groupchats(仅浅灰色部分)的小部件:
class GroupchatWidget extends StatefulWidget {
Groupchat groupchat;
@override
State<GroupchatWidget> createState() => _GroupchatWidgetState();
GroupchatWidget(this.groupchat, {Key? key}) : super(key: key);
}
class _GroupchatWidgetState extends State<GroupchatWidget> {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).focusColor,
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FutureBuilder<ImageProvider>(
future: Buttons.getGroupchatImage(widget.groupchat.Id, context),
builder: (BuildContext context,
AsyncSnapshot<ImageProvider> snapshot) {
return CircleAvatar(
radius: 25,
foregroundImage: snapshot.data,
backgroundImage: Settings.DefaultGroupchatImage,
);
},
),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2),
child: Text(
widget.groupchat.Name,
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.bold),
),
),
FutureBuilder<void>(
future: Buttons.getNewGroupchatMessages(
widget.groupchat.Id, context),
builder:
(BuildContext context, AsyncSnapshot<void> snapshot) {
return Text(
Cache.getLastMessage(widget.groupchat.Id).Text,
style: const TextStyle(fontSize: 15),
);
},
),
],
),
),
],
),
),
),
);
}
}
在聊天的NA下(堆栈溢出疯狂)是最后一条消息的文本。但是,当此文本太长时,它会被x像素溢出。这是一个屏幕截图: 我如何防止这种情况?
I am using this code to create widget that shows user's groupchats (only the light gray part):
class GroupchatWidget extends StatefulWidget {
Groupchat groupchat;
@override
State<GroupchatWidget> createState() => _GroupchatWidgetState();
GroupchatWidget(this.groupchat, {Key? key}) : super(key: key);
}
class _GroupchatWidgetState extends State<GroupchatWidget> {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).focusColor,
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FutureBuilder<ImageProvider>(
future: Buttons.getGroupchatImage(widget.groupchat.Id, context),
builder: (BuildContext context,
AsyncSnapshot<ImageProvider> snapshot) {
return CircleAvatar(
radius: 25,
foregroundImage: snapshot.data,
backgroundImage: Settings.DefaultGroupchatImage,
);
},
),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2),
child: Text(
widget.groupchat.Name,
style: const TextStyle(
fontSize: 15, fontWeight: FontWeight.bold),
),
),
FutureBuilder<void>(
future: Buttons.getNewGroupchatMessages(
widget.groupchat.Id, context),
builder:
(BuildContext context, AsyncSnapshot<void> snapshot) {
return Text(
Cache.getLastMessage(widget.groupchat.Id).Text,
style: const TextStyle(fontSize: 15),
);
},
),
],
),
),
],
),
),
),
);
}
}
Under the na of the chat (Stack Overflow madness) is a text from last message. But when this text is too long, it overflows by X pixels. Here is a screenshot:
How do I prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用ListTile小部件。
you can use ListTile Widget.
WARP
列
带有展开
的两个小部件文本,row rilding [
circleavatar
,expaned
expaned &gt;列
儿童[text
,text
]]尝试以下操作:
Warp
Column
of two widget text withExpanded
,Row
children [CircleAvatar
,Expaned
>Column
children [Text
,Text
]]Try this:
或者
or