mapUpdatedEventDataToWidget method

Future<void> mapUpdatedEventDataToWidget(
  1. EventNotificationModel eventData, {
  2. Map? tags,
  3. String? tagOfAtsign,
  4. bool updateLatLng = false,
  5. bool updateOnlyCreator = false,
})

Updates any EventKeyLocationModel data for updated data

Implementation

Future<void> mapUpdatedEventDataToWidget(EventNotificationModel eventData,
    {Map<dynamic, dynamic>? tags,
    String? tagOfAtsign,
    bool updateLatLng = false,
    bool updateOnlyCreator = false}) async {
  String neweventDataKeyId;
  neweventDataKeyId = eventData.key!
      .split('${MixedConstants.CREATE_EVENT}-')[1]
      .split('@')[0];

  for (var i = 0; i < allEventNotifications.length; i++) {
    if (allEventNotifications[i]
        .eventNotificationModel!
        .key!
        .contains(neweventDataKeyId)) {
      /// if we want to update everything
      // allEventNotifications[i].eventNotificationModel = eventData;

      /// For events send tags of group members if we have and update only them
      if (updateOnlyCreator) {
        /// So that creator doesnt update group details
        eventData.group =
            allEventNotifications[i].eventNotificationModel!.group;
      }

      if ((tags != null) && (tagOfAtsign != null)) {
        allEventNotifications[i]
            .eventNotificationModel!
            .group!
            .members!
            .where((element) => element.atSign == tagOfAtsign)
            .forEach((element) {
          if (updateLatLng) {
            element.tags!['lat'] = tags['lat'];
            element.tags!['long'] = tags['long'];
          } else {
            element.tags = tags;
          }
        });
      } else {
        allEventNotifications[i].eventNotificationModel = eventData;
      }

      allEventNotifications[i].eventNotificationModel!.key =
          allEventNotifications[i].eventNotificationModel!.key;

      notifyListeners();

      await updateLocationDataForExistingEvent(eventData);

      break;
    }
  }
}