The argument type 'List<BatchRecord>' can't be assigned to the parameter type 'Iterable<BatchTiming>'

Issue

The argument type ‘List’ can’t be assigned to the parameter type ‘Iterable’. I am facing the issue while try to add data to a list.

getBatchDates() async {
    try {
      isLoading(true);

      var batchDates = await api.getUserEnrollmentBatches();

      if (batchDates != null) {
        return BatchDate.assignAll(batchDates);
      }
    } finally {
      isLoading(false);
    }
  }

enter image description here

Solution

Make sure api.getUserEnrollmentBatches() is returning List<BatchDate>, then use _myList.addAll(batchDates) instead BatchDate.assignAll(batchDates).

var List<BatchDate> _myList = []; // Something inside

List<BatchDate> getBatchDates() async {
    try {
      isLoading(true);

      var batchDates = await api.getUserEnrollmentBatches();

      if (batchDates != null) {
        return _myList.addAll(batchDates);
      }
    } finally {
      isLoading(false);
    }
  }

Answered By – Johan Ordenes Galleguillos

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *