Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove blank space in AlertDialog?

Tags:

flutter

dart

I wanted to show an AlertDialog that prompts the user for picking a color. I did it, however, there is a lot of blank space between the ColorPicker and the action buttons:

enter image description here

How can I remove the blank space and make the dialog only as big as it should be? I have tried using a Dialog instead of an AlertDialog, and also wrapping my content inside a Column with mainAxisSize set to MainAxisSize.min, but neither worked. One curious thing is that the value passed to contentPadding seems to cause no effect on the UI. I have tried different values and it keeps the same.

This is the code:

void _showColorPickerDialog() {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            contentPadding: const EdgeInsets.all(6.0),
            title: Text('Pick a color'),
            content: MaterialColorPicker(),
            actions: [
              FlatButton(
                  child: Text('CANCEL', style: TextStyle(color: Colors.blue)),
                  onPressed: Navigator.of(context).pop),
              FlatButton(
                  child: Text('OK', style: TextStyle(color: Colors.blue)),
                  onPressed: Navigator.of(context).pop),
            ],
          );
        });
  }

The (Material ColorPicker) package's author provides some code showing how to do this, which is quite similar to mine, but it has the same problem. Maybe my Flutter version is not the same as his. Anyways, do you guys know any good approach to solve this? Thanks in advance.

like image 535
Allan Juan Avatar asked Oct 20 '25 04:10

Allan Juan


1 Answers

Maybe it can works; Give height to MaterialColorPicker function

content: Container(height:250, child: MaterialColorPicker(),)

like image 89
burakozyurt Avatar answered Oct 22 '25 18:10

burakozyurt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!