RenderShrinkWrappingViewport does not support returning intrinsic dimensions

I want a text button when on click shows a simpleDialog vith a listView.builder but I don’t know how to code it. I always have an error.
Can you help me?

Here is my code:

TextButton(
    child: const Text('Selet instruments needed'),
    onPressed: () {
      showDialog(
          context: context,
          builder: (BuildContext context) => SimpleDialog(
                  contentPadding: const EdgeInsets.all(15),
                  title: const Text('Select instruments needed'),
                  children: [
                    ListView.builder(
                        shrinkWrap: true,
                        itemCount: 2,
                        itemBuilder: ((context, index) {
                          return ListTile(
                              title: instrumentType[index]['name'],
                              onTap: () {});
                        }))
                  ]));
    })

>Solution :

You can wrap your ListView with SizedBox widget and using LayoutBuilder help to get the constraints

  TextButton(
        child: const Text('Selet instruments needed'),
        onPressed: () {
          showDialog(
            context: context,
            builder: (BuildContext context) => LayoutBuilder(
              builder: (context, constraints) => SimpleDialog(
                contentPadding: const EdgeInsets.all(15),
                title: const Text('Select instruments needed'),
                children: [
                  SizedBox(
                    height: constraints.maxHeight * .7, // 70% height
                    width: constraints.maxWidth * .9,
                    child: ListView.builder(
                      physics: NeverScrollableScrollPhysics(),
                      itemCount: 44,
                      itemBuilder: ((context, index) {
                        return ListTile(onTap: () {});
                      }),
                    ),
                  )
                ],
              ),
            ),
          );
        })

Leave a Reply