listview - 对话框中的 ListView ,适合文本

标签 listview flutter dart dialog

我有这个自定义对话框,其中包含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,
            )),
      ],
    );
  }

问题是当字符串太长时=>

overflow

问题是由于字符串长度导致底部溢出。

有关如何使其工作的任何建议?谢谢

最佳答案

您可以使用此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/

相关文章:

jquery - Listview切完整句-jquery mobile

android - 如何创建一个共享首选项的单个实例,它可以在 flutter 的整个项目中使用

dart - 将方法作为参数传递给小部件

c# - 在 Xamarin.Forms 中获取 ListView 的选定项的 ID

android - OnItemClick 和 OnItemLongClick 在仅将 Button 放入 ListView 时不起作用

flutter - 如何在没有构建器的情况下将 Dart 模型类转换为列表?

flutter - 如何在 flutter 中修复 'Text is null'

dart - SliverAppBar 和 Listview 与 Controller

android - 有没有办法在更新数据后刷新 baseadapter 中的自定义 View ?

google-maps - 官方谷歌地图绘制路线