Flutter showDatePicker';s头溢出错误
您好,我对颤振中的日期选择器有一个问题,当从步进器的步骤中调用它时: 我正在从此步骤调用showDateTimePicker:Flutter showDatePicker';s头溢出错误,flutter,flutter-layout,Flutter,Flutter Layout,您好,我对颤振中的日期选择器有一个问题,当从步进器的步骤中调用它时: 我正在从此步骤调用showDateTimePicker: new Step( title: new Text( 'Día', style: TextStyle( color: Theme.of(context).primaryColor, ), ), content: Container( height:
new Step(
title: new Text(
'Día',
style: TextStyle(
color: Theme.of(context).primaryColor,
),
),
content: Container(
height: MediaQuery.of(context).size.width - 100.0,
child: ListView(
children: <Widget>[
DateTimePickerFormField(
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 25.0,
),
format: DateFormat('dd/MM/yyyy - hh:mm'),
onChanged: (date) {
if (date != null) print(date.toIso8601String());
},
),
],
),
),
isActive: _currentStep >= 0,
state: _currentStep >= 0 ? StepState.complete : StepState.disabled,
),
也许有人解决了这个问题?您也可以将颤振的日期选择器和时间选择器堆叠起来,而不是使用datetime\u picker\u formfield:
Future _pickDate() async {
DateTime pickedDate = await showDatePicker(
context: context,
initialDate: _date,
firstDate: _firstDate,
lastDate: _lastDate,
);
TimeOfDay pickedTime = await showTimePicker(
context: context,
initialTime: _time,
);
if(pickedDate != null && pickedTime != null) {
DateTime _newStamp = new DateTime(pickedDate.year, pickedDate.month, pickedDate.day, pickedTime.hour, pickedTime.minute);
setState(() {
_time = pickedTime;
_date = pickedDate;
_stamp = _newStamp;
});
}
}
解决此问题的部分是SingleChildScrollView和data:Theme.of(context).copyWith(primaryTextTheme:TextTheme(display1:TextStyle(fontSize:30))
看起来25.0的字体大小有点太大了。试试23.0或21.0。日期选择器对话框的布局似乎没有太多选项。这里的fontsize应用于textformfield而不是DatePicker小部件,但是我更改了它,结果相同,谢谢你的建议。我认为这是一个错误,我将date_picker.dart中的DatePicker高度常量从100更改为115,现在它消失了,由于某些原因,它已损坏。您的“showDatePicker”在哪里?或者您是否给出了错误的标题?您好,在添加datetime\u picker\u formfield软件包之前,我尝试了标准软件包,但出现了完全相同的错误。也试着在手机上测试这个三星Galaxy Note 8(有足够的屏幕空间)和同样的错误。你能考虑在你的答案中添加一些解释,描述哪些部分解决了原来的问题,以及如何解决?
Future _pickDate() async {
DateTime pickedDate = await showDatePicker(
context: context,
initialDate: _date,
firstDate: _firstDate,
lastDate: _lastDate,
);
TimeOfDay pickedTime = await showTimePicker(
context: context,
initialTime: _time,
);
if(pickedDate != null && pickedTime != null) {
DateTime _newStamp = new DateTime(pickedDate.year, pickedDate.month, pickedDate.day, pickedTime.hour, pickedTime.minute);
setState(() {
_time = pickedTime;
_date = pickedDate;
_stamp = _newStamp;
});
}
}
showDatePicker(
context: context,
initialDate: initDate ?? DateTime.now(),
firstDate: firstDate ?? DateTime(1919),
lastDate: lastDate ?? DateTime.now(),
builder: (context, child) {
return SingleChildScrollView(
child: Theme(
isMaterialAppTheme: true,
data: Theme.of(context).copyWith(primaryTextTheme: TextTheme(display1: TextStyle(fontSize: 30))),
child: child
),
);
});```