为什么我收到此错误警告:支持空的操作的操作数的类型为';颜色';,该类型不包括空 [英] Why im getting this error Warning: Operand of null-aware operation '??' has type 'Color' which excludes null
本文介绍了为什么我收到此错误警告:支持空的操作的操作数的类型为';颜色';,该类型不包括空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此程序包
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,
^
一切运行正常,我不知道为什么会出现这个错误。如果您需要更多信息,请留言。希望有人知道怎么解决这个问题。如果您需要任何其他信息,也请留言
推荐答案
这不是错误,而是来自flutter_datetime_picker
包的警告,表明它尚未完全更新其代码,使其完全习惯于使用空安全性。基本上,它使用??
运算符来应对theme.backgroundColor
为空的可能性,但现在theme.backgroundColor
被标记为不可为空,因此运算符是多余的。弹出警告很烦人,但它不会以任何方式影响你的应用程序。
请注意,代码已在master branch of the package repository中正确更新,因此下次发布包时,该警告将消失。
编辑:从1.5.1版开始,此程序包正式支持空安全。该修复程序是在1.5.1发布后通过拉入请求添加的,因此下一个版本(1.5.2或更高版本)应该会解决此问题。
这篇关于为什么我收到此错误警告:支持空的操作的操作数的类型为';颜色';,该类型不包括空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文