Home > Software engineering >  Horizontal listview in alertdialog
Horizontal listview in alertdialog

Time:08-11

I am making todo app where I want a alertdialong containing fields for title, description and note colour..

For selecting color I want to have a container that contains Listview horizontally for color options...but its showing an error

RenderViewport does not support returning intrinsic dimensions.

What should I correct in my code for it

here is my code

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],
                    ),
                  );
                }),)
          ],
        ),
      ),
    );
  }

CodePudding user response:

Give width to the container like

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],
                    ),
                  );
                }),)
  • Related