Trying to show a Dialog with title and close button like the following:
------------------------------
| Title [x] |
| |
| This is dialog content. |
|----------------------------|
Dialog size should be wrapping its content dynamically (not maximized, width not hard-coded).
The close icon is on the top right corner.
Dialog(child:
Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text('This is Title'),
Expanded(
child: Align(
alignment: Alignment.topRight,
child: IconButton(
icon: const Icon(Icons.close)),
),
)
],
),
// content widget goes here
],
)
);
The Expanded will maximize the dialog width (about 90% of screen width). If the Expanded is removed, the header row width is minimized.
How to make the header row have the same width as dialog content so that the close icon is on the top right corner?
2
Answers
You can use Wrap Widget to wrap teh dialog,
also you can play with
shape
property in dialog to modify sizehere is full code for using Wrap widget.
You can try mainAxisAlignment : MainAxisAlignment.spaceBetween instead and remove the expanded widget