方法 '*' 在 null 上调用。接收器:空 尝试呼叫:*(2)



我真的不知道是什么导致了这个错误。我试图删除函数sunday((,因为我认为这可能是问题的原因,但问题仍然存在。我还尝试删除selectableDayPredicate,但问题仍然存在。我的小部件树有点长,很抱歉读得太长。感谢您的帮助!这是我的代码:


class TaskScreen extends StatefulWidget {
@override
_TaskScreenState createState() => _TaskScreenState();
}
class _TaskScreenState extends State<TaskScreen> {
DateTime sunday() {
_date = DateTime.now();
if (_date.weekday == 1) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 6);
}
if (_date.weekday == 2) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 5);
}
if (_date.weekday == 3) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 4);
}
if (_date.weekday == 4) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 3);
}
if (_date.weekday == 5) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 2);
}
if (_date.weekday == 6) {
_date = DateTime.utc(_date.year, _date.month, _date.weekday + 1);
}
return _date;
}
final searchFocusNode = FocusNode();
DateTime _date = DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
DateTime _datePicker = await showDatePicker(
context: context,
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.light().copyWith(
primaryColor: Color.fromRGBO(66, 87, 184, 1),
accentColor: Color.fromRGBO(56, 85, 144, 1),
colorScheme: ColorScheme.light(
primary: const Color.fromRGBO(66, 87, 184, 1)),
buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
),
child: child,
);
},
initialDate: sunday(),
firstDate: DateTime(1947),
lastDate: DateTime(2030),
selectableDayPredicate: (day) => day.weekday == 7 ? true : false,
);
if (_datePicker != null && _datePicker != _date) {
setState(() {
_date = _datePicker;
});
}
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: SizeConfig.gridSizeHeight * 2),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
iconSize: 40,
focusNode: searchFocusNode,
color: Color.fromRGBO(66, 87, 184, 1),
),
SizedBox(
width: SizeConfig.gridSizeWidth * 80,
child: TextFormField(
focusNode: searchFocusNode,
decoration: InputDecoration(
hintText: "Search",
),
onFieldSubmitted: (_) {},
),
),
],
),
SizedBox(
height: SizeConfig.gridSizeHeight * 0.1,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
icon: Icon(
Icons.date_range,
color: Color.fromRGBO(66, 87, 184, 1),
),
iconSize: 40,
onPressed: () {
setState(() {
_selectDate(context);
});
}),
Column(
children: [
Container(
width: SizeConfig.gridSizeWidth * 80,
child: TextFormField(
initialValue: "${_date.year}-${_date.month}-${_date.day}",
cursorColor: Color.fromRGBO(66, 87, 184, 1),
readOnly: true,
onTap: () {
setState(() {
_selectDate(context);
});
},
decoration: InputDecoration(
labelText: "Date",
hintText: "${_date.year}-${_date.month}-${_date.day}",
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color.fromRGBO(66, 87, 184, 1),
width: 2,
)),
),
),
),
],
),
],
),
SizedBox(
height: SizeConfig.gridSizeHeight * 2,
),
Padding(padding: const EdgeInsets.all(5)),
Expanded(
child: ListView.builder(
itemBuilder: (ctx, index) {
return Column(
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.gridSizeWidth * 3,
vertical: SizeConfig.gridSizeHeight,
),
margin: EdgeInsets.symmetric(
horizontal: SizeConfig.gridSizeWidth * 7.5,
vertical: SizeConfig.gridSizeHeight * 2,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
children: [
Text(
"Project Name: ",
style: TextStyle(
color: Color.fromRGBO(66, 87, 184, 1),
),
),
Padding(
padding: const EdgeInsets.all(0.5),
),
Text("Telecom Egypt"),
],
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeHeight * 0.5),
),
Row(
children: [
Text(
"Task Code: ",
style: TextStyle(
color: Color.fromRGBO(66, 87, 184, 1),
),
),
Text("#1235"),
],
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeHeight * 0.5),
),
Row(
children: [
Text(
"Project Manager: ",
style: TextStyle(
color: Color.fromRGBO(66, 87, 184, 1),
),
),
Text("Khaled Khalifa"),
],
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeHeight * 0.5),
),
Row(
children: [
Text(
"Time: ",
style: TextStyle(
color: Color.fromRGBO(66, 87, 184, 1),
),
),
Text("8 Hours"),
],
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeHeight * 0.5),
),
Row(
children: [
Text(
"Priority: ",
style: TextStyle(
color: Color.fromRGBO(66, 87, 184, 1),
),
),
Text("1"),
],
),
SizedBox(
height: SizeConfig.gridSizeHeight,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
Icons.remove_red_eye,
color: Color.fromRGBO(66, 87, 184, 1),
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeWidth),
),
Icon(
Icons.edit,
color: Color.fromRGBO(66, 87, 184, 1),
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeWidth),
),
Icon(
Icons.comment,
color: Color.fromRGBO(66, 87, 184, 1),
),
Padding(
padding:
EdgeInsets.all(SizeConfig.gridSizeWidth),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.clear,
color: Colors.red,
),
Padding(
padding: EdgeInsets.all(
SizeConfig.gridSizeWidth),
),
Icon(
Icons.check,
color: Color.fromRGBO(56, 85, 144, 1),
),
],
))
],
),
],
),
decoration: BoxDecoration(
border: Border.all(
color: Color.fromRGBO(66, 87, 184, 1),
width: 1,
),
),
),
index == 2
? SizedBox(
height: SizeConfig.gridSizeHeight * 7,
)
: SizedBox()
],
);
},
itemCount: 3,
),
),
],
),
);
}
}

您发布的错误消息说,*是在null上调用的,这意味着null变量上有一个multiplication操作。

代码中有一个变量:

SizeConfig.gridSizeHeight

SizeConfig.gridSizeWidth

其在许多地方是CCD_ 5。该变量的值在某个时刻为null,这可能会导致异常。

请检查SizeConfig,并确保变量gridSizeHeightgridSizeWidth不是null

相关内容

  • 没有找到相关文章

最新更新