У меня есть VoidCallback, переданный из виджета в другой, при вызове из второго виджета он функционирует нормально, если я добавляю 'await' к другому оператору в той же функции, он ломается и показывает ошибку "call on null"
Первый виджет:
refreshLocalList() async {
Logger.log("Refrishing list");
setState(() {appointmentsList=AppointmentsController.getLocalList();});
}
.
.
.
onTap: (){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => NewAppointment(time:times9to2[index],date: date,cameraId: cameraId.toString(),refreshLocalList: refreshLocalList,showInSnackBar: showInSnackBar,)));
},
Второй виджет:
class NewAppointment extends StatefulWidget {
final String time;
final String date;
final String cameraId;
final VoidCallback refreshLocalList;
final void Function(String msg) showInSnackBar;
const NewAppointment({Key key, this.time, this.date,this.cameraId,this.refreshLocalList,this.showInSnackBar}) : super(key: key);
@override
_NewAppointmentState createState() => _NewAppointmentState();
}
class _NewAppointmentState extends State<NewAppointment> {
Doctor doctor = Doctor();
_NewAppointmentState();
Widget build(BuildContext context) {
return MaterialApp(
.
.
.
child: Text("Submit",
),
onPressed: () async {
widget.refreshLocalList();
Appointment newAppointmet = Appointment(doctor_id: DoctorsController.getDoctorIdByName(doctorNameController.text),
date: widget.date,time: widget.time,description: descriptionFieldController.text,camera_id: widget.cameraId);
AppointmentsController.addToLocalList(newAppointmet);
await Queries.createAppointment(doctorNameController.text,widget.date,widget.time,descriptionFieldController.text,widget.cameraId);
Navigator.of(context).pop();
widget.showInSnackBar("Appointment created");
}),
обратный вызов refreshLocalList()
другой обратный вызов widget.showInSnackBar(String)
отлично работает в обоих случаях.
если я уберу "await" до Queries.createAppointment
, все будет нормально.
Ошибка:
> I/flutter (14062): full doctors map size 57 E/flutter (14062):
> [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception:
> NoSuchMethodError: The method 'call' was called on null. E/flutter
> (14062): Receiver: null E/flutter (14062): Tried calling: call()