【问题标题】:Horizontal listview in alertdialog警报对话框中的水平列表视图
【发布时间】:2022-08-10 23:02:24
【问题描述】:

我正在制作待办事项应用程序,我想要一个包含标题、描述和注释颜色字段的警报拨号。

为了选择颜色,我想要一个包含水平颜色选项的 Listview 的容器......但它显示错误

RenderViewport does not support returning intrinsic dimensions.

我应该在我的代码中纠正什么

这是我的代码

Widget build(BuildContext context) {
    return AlertDialog(
      content: Form(
        key: _form,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              \'Add Todo\',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
            ),
            SizedBox(
              height: 10,
            ),
            buildtitle(),
            SizedBox(
              height: 10,
            ),
            builddescription(),
            SizedBox(
              height: 10,
            ),
            buildsavebutton(),
            SizedBox(height: 10,),
            Container(
              height: 40,
               child: ListView.builder(
                 scrollDirection: Axis.horizontal,
                itemCount: mycolors.length,
                itemBuilder: (context,index){
                  return GestureDetector(
                    onTap: (){

                    },
                    child: Container(
                      height: 20,
                      width: 20,
                      color: mycolors[index],
                    ),
                  );
                }),)
          ],
        ),
      ),
    );
  }

    标签: flutter dart


    【解决方案1】:

    给容器宽度,比如

    Container(
                  height: 40,
             width: MediaQuery.of(context).size.width*0.6, //<--- here
                   child: ListView.builder(
                     scrollDirection: Axis.horizontal,
                    itemCount: mycolors.length,
                    itemBuilder: (context,index){
                      return GestureDetector(
                        onTap: (){
    
                        },
                        child: Container(
                          height: 20,
                          width: 20,
                          color: mycolors[index],
                        ),
                      );
                    }),)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      相关资源
      最近更新 更多