我真的不知道是什么导致了此错误。我试着删除函数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,
),
),
],
),
);
}
}
答案 0 :(得分:0)
您发布的错误消息说*
被调用null
,这意味着multiplication
变量上有一个null
操作。
在代码中,您有一个变量:
SizeConfig.gridSizeHeight
AND
SizeConfig.gridSizeWidth
在很多地方都是multiplied
,用于调整大小。在某个时候,该变量的值为null
,这可能会导致异常。
请检查SizeConfig
并确保变量gridSizeHeight
或gridSizeWidth
不是null
。