I am new to Flutter and the Dart programming language. I am making a shift-assignment app, but am stuck on this - I need to return a string from an async function which also waits for a value from other async functions. This is what I have written so far:
Future<String> getNumberOfShiftsText() async {
int weekShiftCount = 0;
List<DateTime> shiftTimes = [];
await getUserDetailsFromServer().then((value){
await getAppointmentsFromServer(cid, isEmployer, rolesList).then((aValue) {
List<HiveAppointment> appointmentList = appointmentBox.values.toList();
for (int i = 0; i < appointmentList.length; i++) {
if (appointmentList[i].startTime.isBefore(DateTime.now().add(const Duration(days: 7)))) {
weekShiftCount += 1;
shiftTimes.add(appointmentList[i].startTime);
}
}
});
});
return Future.delayed(const Duration(seconds: 1), () => '$weekShiftCount shift(s) assigned to you in the next 7 days',);
}
On running this, I get the error:
A non-null value must be returned since the return type 'String' doesn't allow null. Future getNumberOfShiftsText() async {
Any ideas on how I can solve this? Any help would be much appreciated. Thanks in advance, and I apologize for my lack of knowledge.