【问题标题】:how to display listview inside alert in flutter如何在颤动的警报中显示列表视图
【发布时间】:2020-04-02 12:32:31
【问题描述】:

我正在使用 rflutter_alert 插件在我的应用程序中使用 Flutter 处理警报 但是当我将 listView 用于参数内容时,我遇到了问题 Text 等其他小部件可以正常工作

我收到以下错误

渲染库捕捉到异常═════════════════════════════════════════ ═══════════ 在 performLayout() 期间引发了以下断言: RenderViewport 不支持返回固有尺寸。

Expanded(
  child: Card(
    child: ListView.builder(
        itemCount: content.length,
        itemBuilder: (ctx, index) {
          return ListTile(title: Text(content[index]["doctor_name"]),
          onTap: (){
            Alert(
              context: context,
              title: doctors[index]["doctor_name"],
              content: ListView(children: <Widget>[
                Text(doctors[index]["major"]),
                Text(doctors[index]["hospital"]),
              ],)
            ).show();
          },
          );
        }),
  ),
)

这是连接网址 rflutter_alert

你能帮忙解决这个问题吗?

【问题讨论】:

    标签: android flutter cross-platform flutter-layout


    【解决方案1】:

    您可以尝试将其包装到容器中并设置宽度/高度

       onTap: (){
            Alert(
              context: context,
              title: doctors[index]["doctor_name"],
              content: Container(
                width: 100,
                height: 100,
                child: ListView(children: <Widget>[
                   Text(doctors[index]["major"]),
                   Text(doctors[index]["hospital"]),
              ],))
            ).show();
    

    【讨论】:

      【解决方案2】:

      您需要在警报对话框的ListView 中添加shrinkWrap: true

      如下所示。

            ListView.builder(
                itemCount: 10,
                itemBuilder: (ctx, index) {
                  return ListTile(
                    title: Text('$index'),
                    onTap: () {
                      Alert(
                        context: context,
                        title: 'Title',
                        content: ListView(
                          shrinkWrap: true, // Like here
                          children: <Widget>[
                            Text('Test'),
                            Text('Test'),
                          ],
                        ),
                      ).show();
                    },
                  );
                }),
      

      【讨论】:

        猜你喜欢
        • 2020-07-08
        • 1970-01-01
        • 2013-03-23
        • 2020-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-19
        相关资源
        最近更新 更多