0

I have been trying to debug what is going wrong but the only solution is removing the inTasks.add(res) because the loop freezes at that point, so is managing data within a Future not allowed in dart/flutter is there a better way to do this, i also get no errors and I've tried uisng global variables with no luck.

Future<List> getWeekly(DateTime date) async {
  List inTasks;
  for (var i = 0; i < 7; i++) {
    var params = {'date': date.toIso8601String()};
    Uri uri = Uri.parse('URL');
    final newURI = uri.replace(queryParameters: params);
    http.Response response = await http.get(
      newURI,
      headers: {"Accept": "application/json"},
    );
    var res = json.decode(response.body);
    date.add(Duration(days: i));
    inTasks.add(res);
    return inTasks;
  }
}
2
  • 2
    You didn't initialize the list inTasks. Try List inTasks = []; Jul 27, 2020 at 19:01
  • Yes %100 correct, i cannot such a simple mistake took so much time from me. Thank You so much!! Jul 28, 2020 at 0:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.