flutter listview with radio not showing in alertDialog

Viewed 1104

This is the code. code:

  class ThemeChangerWidget extends StatelessWidget {
  final List<String> string = ['Light', 'Dark', 'Amoled'];
  @override
  Widget build(BuildContext context) {
  final stateData = Provider.of<ThemeNotifier>(context);
  final ThemeData state = stateData.getTheme();

  return Theme(
  data: state.copyWith(unselectedWidgetColor: state.accentColor),
  child: AlertDialog(
      backgroundColor: state.primaryColor,
      shape:
          RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
      title: Text('Select Theme', style: state.textTheme.body1),
      content: ListView.builder(
        shrinkWrap: true,
        itemBuilder: (context, index) {
          return RadioListTile(
            value: index,
            groupValue: themes.indexOf(state),
            onChanged: (ind) {
              onThemeChanged(ind, stateData);
            },
            title: Text(
              string[index],
              style: state.textTheme.body2,
            ),
          );
        },
        itemCount: string.length,
      )),
      );
     }
     }'

errors-The following assertion was thrown during performLayout():

RenderShrinkWrappingViewport does not support returning intrinsic dimensions.

some times throw this error instead of above LayoutBuilder does not support returning intrinsic dimensions.

Calculating the intrinsic dimensions would require instantiating every child of the viewport, which defeats the point of viewports being lazy. If you are merely trying to shrink-wrap the viewport in the main axis direction, you should be able to achieve that effect by just giving the viewport loose constraints, without needing to measure its intrinsic dimensions.

enter image description here

1 Answers

AlertDialog uses an IntrinsicWidth widget that doesn't allow ListView.builder. You have to give a specific width to your ListView Example:

    return AlertDialog(
      title: Text('Dialog'),
      content: SizedBox(
        width: double.maxFinite,
        child: ListView(
          children: <Widget>[
           //Your content here
          ],
        ),
      ),
    );
Related