Hi I'm new to Flutter and I got in trouble with the exception "RenderBox was not laid out". I'm trying to create MyDialog
which is an extension of the built-in dialog. It can be injected contents from other widget. And I wanna place Expanded
widget wrapping Text
widget as the contents so that all text can be seen with line breaks.
I intent the contents show like this:
This is my MyDialog
widget.
class MyDialog extends StatelessWidget {
String label;
Widget contents;
const MyDialog({required this.label, required this.contents, Key? key}) : super(key : key)
@override
Widget build(BuildContext context) {
return MyButtonTip( // This is an extension of outlined button.
label : label,
onPressed : () {
showDialog(
context : context,
builder : (BuildContext context) => AlertDialog(
insetPadding : const EdgeInsets.all(15),
content : SizedBox(
width : MediaQuery.of(context).size.width,
child : contents
)
)
);
}
);
}
}
And this is the widget that uses MyDialog
.
...
MyDialog(
label : 'Profile',
contents : SizedBox(
child : Stack(
children : [
Column(
children : [
Row(
children : [
Column(
crossAxisAlignment : CrossAxisAlignment.end,
children : const [
Text('name'),
Text('nickname')
]
),
const SizedBox(width : 10),
Column(
crossAxisAlignment : CrossAxisAlignment.start,
children : [
Text(name),
Expanded(
child : Text(nickname)
)
]
)
]
)
]
)
]
))
)
);
...
(I'm using Stack
for aiming something different, so please don't care about it.)
I would like to know the correct solution, as I have encountered this exception many times before and each time it has somehow been resolved. Please let me know in detail.
Thanks,
As my opinion you placed widget wrong please try with below code:
MyDialog(
label : 'Profile',
contents : Column(children: [
Row(children: const [
Text('name : '),
Text("hello"),
]),
const SizedBox(width: 10),
Row(crossAxisAlignment: CrossAxisAlignment.start, children: const [
Text('taro yamuda : '),
Expanded(
child: Text(
"someting sometingsometingsometingsometingsometingsometingsometingsometingsometingsometingsometingsometing",
style: TextStyle(),
),
)
])
]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.