I have model Like This :

Model

class ActivityModel {
  String idActivity;
  String titleActivity;
  String dateTimeActivity;
  int isDoneActivity;
  int codeIconActivity;
  String informationActivity;
  String createdDateActivity;

  ActivityModel({
    this.idActivity,
    this.titleActivity,
    this.dateTimeActivity,
    this.isDoneActivity,
    this.codeIconActivity,
    this.informationActivity,
    this.createdDateActivity,
  });

ActivityModel.fromSqflite(Map<String, dynamic> map)
      : idActivity = map['id_activity'],
        titleActivity = map['title_activity'],
        dateTimeActivity = map['datetime_activity'],
        isDoneActivity = map['is_done_activity'],
        codeIconActivity = map['code_icon_activity'],
        informationActivity = map['information_activity'],
        createdDateActivity = map['created_date'];

  Map<String, dynamic> toMapForSqflite() {
    return {
      'id_activity': this.idActivity,
      'title_activity': this.titleActivity,
      'datetime_activity': this.dateTimeActivity,
      'is_done_activity': this.isDoneActivity,
      'code_icon_activity': this.codeIconActivity,
      'information_activity': this.informationActivity,
      'created_date': this.createdDateActivity,
    };
  }

I want get data where dateTimeActivity is before than date now, then i update isDoneActivity = 1 with this code :

Source code

final passedDateItem = _selectedActivityItem.where((element) {
      DateTime convertStringToDateTime =
          DateTime.parse(element.dateTimeActivity);
      return convertStringToDateTime.isBefore(DateTime.now());
    });
  if (passedDateItem != null) {
      print('Not Null');
    } else {
      print('Nulledd');
      return null;
    }

The problem is , passedDateItem return Iterable[ActivityModel] , it's possible to convert it to ActivityModel? So i can easly update like this ?

 if (passedDateItem != null) {
      passedDateItem.isDoneActivity = 1; <<<
      // return passedDateItem.map((e) => e.isDoneActivity = 1);
      //  final testtt= passedDateItem.
      print('Not Null');
    } else {
      print('Nulledd');
      return null;
    }


Solution 1: shb

Iterate through passedDateItem

for (var activityModel in passedDateItem) {
  //..conditions
  activityModel.isDoneActivity = 1;
}

If you are only interested in the first/last element of passedDateItem use

passedDateItem.first.isDoneActivity == 1

or

passedDateItem.last.isDoneActivity == 1

make sure passedDateItem is not empty in that case.