Home > Software engineering >  The argument type 'List<BatchRecord>' can't be assigned to the parameter type &
The argument type 'List<BatchRecord>' can't be assigned to the parameter type &

Time:09-14

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

CodePudding user response:

A List class implemets Iterable class. They arnot the same thing. You have to change your List to Iterable. But also if your class BatchRecord isn't a subclass of BatchTiming you also won't be able to assign it to parameter

CodePudding user response:

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);
    }
  }
  • Related