I’m trying to make my dialog auto-size to fit all it’s content using MainAxisSize.min in my Scaffold Column widget, but I’m still getting the widget at his full length. Why the MainAxisSize.min doesn’t work here?
This is the code of dialog:
class AddSockPopup extends Dialog {
const AddSockPopup({super.key});
@override
Widget build(BuildContext context) {
return StatefulBuilder(
builder: (context, StateSetter setState){
return Dialog(
elevation: 0,
backgroundColor: Colors.transparent,
child: _buildChild(context, setState),
);
},
);
}
_buildChild(BuildContext context, StateSetter setState) {
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)),
child: Scaffold(
backgroundColor: Colors.grey[300],
appBar: AppBar(
title: Text('Sock details'),
centerTitle: true,
backgroundColor: Colors.purple[400],
automaticallyImplyLeading: false,
),
body: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [...],
),
),
),
);
}
}
2
Answers
Wrap your
Scaffold
withColumn
and setmainAxisSize: MainAxisSize.min
:@Babushka Use the
ConstrainedBox
widget to allow for dynamic height adjustment of the dialog. It will automatically adjust based on your content.I hope this will help!