EDIT
Using the methods I tried, and the answers I got I couldn't achieve the auto-size effect and always got the dialog at its full height, so I switched from using Scaffold to Containers. If there is a checked way of doing it with Scaffold feel free to post it. Thanks.
Question
I'm trying to make my dialog auto-size to fit all its content using MainAxisSize.min in my Scaffold Column widget, but I'm still getting the widget at its 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: [...],
),
),
),
);
}
}
Wrap your
ScaffoldwithColumnand setmainAxisSize: MainAxisSize.min: