我正在使用这个软件包
flutter_datetime_picker: ^1.5.1
这是我的代码
String _date = "Please pick Age";
Widget _buildage() {
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
'Enter Age',
style: kLabelStyle,
),
SizedBox(height: 10.0),
Container(
decoration: kBoxDecorationStyle,
alignment: Alignment.centerLeft,
height: 70.0,
child: Container(
child: TextFormField(
initialValue: "haaas",
validator: (val) {
if (val.isEmpty) {
return 'Enter yout Age';
}
if (val.length < 4) {
return 'Enter a username minimun 4 chars long';
}
return null;
},
onChanged: (val) {
setState(() => age = val);
},
onTap: () {
DatePicker.showDatePicker(context,
theme: DatePickerTheme(
containerHeight: 210.0,
),
showTitleActions: true,
minTime: DateTime(2000, 1, 1),
maxTime: DateTime(2022, 12, 31), onConfirm: (date) {
setState(() {
_date = '${date.year} - ${date.month} - ${date.day}';
});
}, currentTime: DateTime.now(), locale: LocaleType.en);
},
readOnly: true,
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 14.0),
prefixIcon: Icon(
Icons.date_range_rounded,
color: Colors.white,
size: 28,
),
hintText: " $_date",
hintStyle: kHintTextStyle,
),
),
),
),
]);
}
错误或警告是这样的
../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_datetime_picker-1.5.1/lib/flutter_datetime_picker.dart:311:32: Warning: Operand of null-aware operation '??' has type 'Color' which excludes null.
- 'Color' is from 'dart:ui'.
color: theme.backgroundColor ?? Colors.white,
^
一切运行正常,但不知道为什么会出现这个错误。如果您需要更多信息,请留言。希望有人知道如何修复它。如果您需要任何其他信息,请也留言。
CupertinoDatePicker
,以匹配iOS的美学)。 - Abion47