日期选择器编辑选项不可用。
我可以通过日历选择输入日期,但编辑选项默认处于禁用状态。
DateTimeField(
readOnly: true,
controller: dobController,
decoration: InputDecoration(
hintText: 'Enter date of birth',
icon: Icon(
Icons.date_range,
color: Colors.grey,
)),
onSaved: (DateTime? val) {
dobDate = val;
// FocusScope.of(context).requestFocus(emailFocus);
},
format: format,
resetIcon: null,
style: AppUtils.textFieldStyle(),
showCursor: false,
onShowPicker: (context, currentValue) {
return showDialog(
context: context,
builder: (BuildContext context) {
return DatePickerDialog(
initialDate: currentValue ?? initialDate,
firstDate: DateTime(1900),
initialEntryMode: DatePickerEntryMode.input,
lastDate: initialDate,
);
},
);
}),
看我的截图。
。
这是输入字段中日期选择器的工作解决方案:
TextFormField(
readOnly: true,
keyboardType: TextInputType.datetime,
autovalidateMode:
AutovalidateMode.onUserInteraction,
autofocus: false,
decoration: InputDecoration(
labelText: 'Date: ',
labelStyle: GoogleFonts.lato(
textStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Color(0xff7C878C),
),
),
,
),
onTap: () async {
DateTime? pickdate =
await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(1950),
lastDate: DateTime(2101),
);
if (pickdate != null) {
setState(() {
_dateTextController.text =
DateFormat("dd-MM-yyyy")
.format(pickdate);
selectedDate = pickdate;
});
}
},
controller: _dateTextController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please Enter Date';
}
return null;
},
),