Flutter 方法'*';在null上调用了。接收方:尝试呼叫:*(2)时为空
我真的不知道是什么导致了这个错误。我试图删除函数sunday(),因为我认为它可能会导致问题,但问题仍然存在。我还尝试删除selectableDayPredicate,但问题仍然存在。我的小部件树有点长,抱歉读得太长。感谢您的帮助!这是我的密码:Flutter 方法'*';在null上调用了。接收方:尝试呼叫:*(2)时为空,flutter,methods,null,Flutter,Methods,Null,我真的不知道是什么导致了这个错误。我试图删除函数sunday(),因为我认为它可能会导致问题,但问题仍然存在。我还尝试删除selectableDayPredicate,但问题仍然存在。我的小部件树有点长,抱歉读得太长。感谢您的帮助!这是我的密码: class TaskScreen extends StatefulWidget { @override _TaskScreenState createState() => _TaskScreenState(); } class _Ta
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,
),
),
],
),
);
}
}
类TaskScreen扩展了StatefulWidget{
@凌驾
_TaskScreenState createState()=>\u TaskScreenState();
}
类_TaskScreenState扩展状态{
日期时间星期日{
_date=DateTime.now();
如果(_date.weekday==1){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+6);
}
如果(_date.weekday==2){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+5);
}
如果(_date.weekday==3){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+4);
}
如果(_date.weekday==4){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+3);
}
如果(_date.weekday==5){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+2);
}
如果(_date.weekday==6){
_日期=DateTime.utc(_date.year、_date.month、_date.weekday+1);
}
返回日期;
}
最终搜索FocusNode=FocusNode();
DateTime _date=DateTime.now();
Future\u selectDate(BuildContext上下文)异步{
DateTime\u datePicker=等待显示datePicker(
上下文:上下文,
生成器:(BuildContext上下文,小部件子项){
返回主题(
数据:ThemeData.light().copyWith(
原色:来自RGBO(66,87,184,1)的颜色,
accentColor:Color.fromRGBO(56,85,144,1),
colorScheme:colorScheme.light(
初级:常量颜色。来自RGBO(66,87,184,1)),
buttonTheme:ButtonThemeData(textTheme:ButtonTextTheme.primary),
),
孩子:孩子,
);
},
起始日期:星期日(),
firstDate:DateTime(1947年),
最后日期:日期时间(2030年),
selectableDayPredicate:(day)=>day.weekday==7?true:false,
);
if(_datePicker!=null&&u datePicker!=u date){
设置状态(){
_日期=_日期选择器;
});
}
}
@凌驾
小部件构建(构建上下文){
返回填充(
填充:边集。对称(垂直:SizeConfig.gridSizeHeight*2),
子:列(
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
图标按钮(
图标:图标(Icons.search),
按下:(){},
iconSize:40,
focusNode:searchFocusNode,
颜色:颜色。来自RGBO(66,87,184,1),
),
大小盒子(
宽度:SizeConfig.gridSizeWidth*80,
子项:TextFormField(
focusNode:searchFocusNode,
装饰:输入装饰(
hintText:“搜索”,
),
onFieldSubmitted:({},
),
),
],
),
大小盒子(
高度:SizeFig.gridSizeHeight*0.1,
),
划船(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
图标按钮(
图标:图标(
Icons.date\u范围,
颜色:颜色。来自RGBO(66,87,184,1),
),
iconSize:40,
已按下:(){
设置状态(){
_选择日期(上下文);
});
}),
纵队(
儿童:[
容器(
宽度:SizeConfig.gridSizeWidth*80,
子项:TextFormField(
初始值:“${{date.year}-${{date.month}-${{date.day}”,
cursorColor:Color.fromRGBO(66,87,184,1),
只读:对,
onTap:(){
设置状态(){
_选择日期(上下文);
});
},
装饰:输入装饰(
标签文本:“日期”,
hintText:“${date.year}-${date.month}-${date.day}”,
聚焦顺序:大纲输入边框(
边界边(
颜色:颜色。来自RGBO(66,87,184,1),
宽度:2,
)),
),
),
),
],
),
],
),
大小盒子(
高度:SizeConfig.gridSizeHeight*2,
),
填充(填充:常量边集所有(5)),
扩大(
子项:ListView.builder(
itemBuilder:(ctx,索引){
返回列(
儿童:[
容器(
填充:EdgeInsets.symmetric(
水平:SizeConfig.gridSizeWidth*3,
垂直:SizeFig.gridSizeHeight,
),
边距:边缘组。对称(
水平:SizeFig.gridSizeWidth*7.5,
垂直:SizeFig.gridSizeHeight*2,
),
子:列(
crossAxisAlignment:crossAxisAlignment.center,
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
划船(
儿童:[
正文(
SizeConfig.gridSizeHeight
SizeConfig.gridSizeWidth