Shrutik Trivedi
Shrutik Trivedi

Reputation: 45

Why dialog box is not opening?

I am trying to open this dialog box ,but whenever i tap on it, it shows me error.

the error i am getting:-LayoutBuilder does not support returning intrinsic dimensions.

 selectImage(parentContext) {
        return showDialog(
            context: parentContext,
            builder: (context) {
              return SafeArea(
                child: SimpleDialog(
                  title: AutoSizeText(
                    "Change profile photo",
                    presetFontSizes: [15, 14, 13, 12, 11],
                    overflow: TextOverflow.visible,
                    maxLines: 1,
                  ),
                  children: <Widget>[
                    SimpleDialogOption(
                        child: Text("Photo with Camera"), onPressed: handleTakePhoto),
                    SimpleDialogOption(
                        child: Text("Image from Gallery"),
                        onPressed: handleChooseFromGallery),
                    SimpleDialogOption(
                      child: Text("Cancel"),
                      onPressed: () => Navigator.pop(context),
                    )
                  ],
                ),
              );
            });
      }

Upvotes: 0

Views: 68

Answers (1)

Code on the Rocks
Code on the Rocks

Reputation: 17794

Anytime you use one dialog inside of another, you need to set an explicit size for the inner dialog. You can use either the Container or SizedBox widget to do this. In your case:

selectImage(parentContext) {
        return showDialog(
            context: parentContext,
            builder: (context) {
              return SafeArea(
                child: Container(
                height:300,
                width: 300,
                child: SimpleDialog(
                  title: AutoSizeText(
                    "Change profile photo",
                    presetFontSizes: [15, 14, 13, 12, 11],
                    overflow: TextOverflow.visible,
                    maxLines: 1,
                  ),
                  children: <Widget>[
                    SimpleDialogOption(
                        child: Text("Photo with Camera"), onPressed: handleTakePhoto),
                    SimpleDialogOption(
                        child: Text("Image from Gallery"),
                        onPressed: handleChooseFromGallery),
                    SimpleDialogOption(
                      child: Text("Cancel"),
                      onPressed: () => Navigator.pop(context),
                    )
                  ],
                ),
),
              );
            });
      }

Upvotes: 1

Related Questions