ModalBottomSheet 中的 CupertinoDatePicker
无法设法将 CupertinoDatePicker 放入 Flutter 的底部模式中。
获取以下信息: RenderCustomMultiChildLayoutBox 对象在布局期间被赋予无限大小。
...
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: IconButton(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Column(
children: [
CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: DateTime.now(),
onDateTimeChanged: (DateTime dateTime) {
// tbd
},
),
ElevatedButton(onPressed: (){}, child: Text("save"))
],
);
});
},
icon: const FaIcon(FontAwesomeIcons.calendar, size:30, color: Colors.orange),
),
)
...
我对 Flutter 太陌生,无法理解如何解决这个问题:
This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
...
The relevant error-causing widget was:
CupertinoDatePicker CupertinoDatePicker
Can't manage to put the CupertinoDatePicker into the bottom modal in Flutter.
Getting the following: RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
...
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: IconButton(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Column(
children: [
CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
initialDateTime: DateTime.now(),
onDateTimeChanged: (DateTime dateTime) {
// tbd
},
),
ElevatedButton(onPressed: (){}, child: Text("save"))
],
);
});
},
icon: const FaIcon(FontAwesomeIcons.calendar, size:30, color: Colors.orange),
),
)
...
I too new to Flutter to understand how I work around this problem :
This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
...
The relevant error-causing widget was:
CupertinoDatePicker CupertinoDatePicker
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
CupertinoDatePicker
小部件在渲染期间获得无限大小。要解决这个问题,您可以使用Container
小部件或SizedBox
小部件包装该小部件,并为其指定一个height
:另一种方法是包装带有
Expanded
小部件的CupertinoDatePicker
。Expanded
小部件使其子部件填充可用空间(而不是尝试填充无限高度)。The problem is the
CupertinoDatePicker
widget gets an infinite size during rendering. To solve that you could wrap the widget with aContainer
widget, or aSizedBox
widget, and giving it aheight
:An alternative is to wrap the
CupertinoDatePicker
with anExpanded
widget. AnExpanded
widget makes its child fill the available space (instead of trying to fill an infinite height).