我有这个自定义对话框,其中包含2个字符串(一个标题,一个内容),我希望将内容视为长字符串的列表 View 。这是我到目前为止所拥有的:
@override
dialogContent(BuildContext context) {
return Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(
top: Consts.avatarRadius + Consts.padding,
bottom: Consts.padding,
left: Consts.padding,
right: Consts.padding,
),
margin: EdgeInsets.only(top: Consts.avatarRadius),
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(Consts.padding),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: const Offset(0.0, 10.0),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
title,
style: TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.bold,
fontFamily: "Rubik1",
),
),
SizedBox(height: 16.0),
Container(
child: ListView(
shrinkWrap: true,
children: <Widget>[
Text(
description,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24.0,
fontFamily: "Rubik1",
),
),
SizedBox(height: 24.0),
Align(
alignment: Alignment.center,
child: RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(16.0),
side: BorderSide(color: Colors.blue)),
onPressed: () {
Navigator.of(context).pop(); // To close the dialog
},
textColor: Colors.white,
color: Colors.blue,
child: Text(
buttonText,
style: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold),
),
),
),
],
),
),
],
),
),
Positioned(
left: MediaQuery.of(context).size.width / 4,
child: CircleAvatar(
backgroundImage: AssetImage(picture),
radius: Consts.avatarRadius,
backgroundColor: Colors.transparent,
)),
],
);
}
问题是当字符串太长时=>
问题是由于字符串长度导致底部溢出。
有关如何使其工作的任何建议?谢谢
最佳答案
您可以使用此Library来防止Widget渲染问题
AutoSizeText(
"description",
textAlign: TextAlign.center,
minFontSize: 18,
maxLines: 16,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 24.0,
fontFamily: "Rubik1",
),
),
关于listview - 对话框中的 ListView ,适合文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60690571/