你好,在步进器的步骤中调用日期选择器时,我遇到了问题:
我从这一步开始调用showDateTimePicker:
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,
),
这是错误堆栈:
I/flutter ( 4388): The specific RenderFlex in question is:
I/flutter ( 4388): RenderFlex#26a8f OVERFLOWING
I/flutter ( 4388): creator: Column ← Padding ← DecoratedBox ← ConstrainedBox ← Container ← _DatePickerHeader ← Column
I/flutter ( 4388): ← SizedBox ← LayoutBuilder ← OrientationBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← ⋯
I/flutter ( 4388): parentData: offset=Offset(16.0, 0.0) (can use size)
I/flutter ( 4388): constraints: BoxConstraints(w=298.0, h=100.0)
I/flutter ( 4388): size: Size(298.0, 100.0)
I/flutter ( 4388): direction: vertical
I/flutter ( 4388): mainAxisAlignment: center
I/flutter ( 4388): mainAxisSize: max
I/flutter ( 4388): crossAxisAlignment: start
I/flutter ( 4388): textDirection: ltr
I/flutter ( 4388): verticalDirection: down
也许有人解决了这个问题?
答案 0 :(得分:0)
您还可以只堆叠flutter的datepicker和timepicker,而不使用datetime_picker_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;
});
}
}
答案 1 :(得分:0)
解决问题的部分是SingleChildScrollView和数据:Theme.of(context).copyWith(primaryTextTheme:TextTheme(display1:TextStyle(fontSize:30))),
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
),
);
});```