createActivity method

Future<String?> createActivity(
  1. String activityId,
  2. Map<String, dynamic> data, {
  3. bool removeWhenAppIsKilled = false,
  4. Duration? staleIn,
})

Create an iOS 16.1+ live activity. When the activity is created, an activity id is returned. Data is a map of key/value pairs that will be transmitted to your iOS extension widget. Files like images are limited by size, be sure to pass only small file size (you can use resizeFactor for images).

StaleIn indicates if a StaleDate should be added to the activity. If the value is null or the Duration is less than 1 minute then no staleDate will be used. The parameter only affects the live activity on iOS 16.2+ and does nothing on on iOS 16.1

Implementation

Future<String?> createActivity(
    String activityId,
    Map<String, dynamic> data, {
      bool removeWhenAppIsKilled = false,
      Duration? staleIn,
    }) async {
  if (defaultTargetPlatform == TargetPlatform.iOS) {
    await _appGroupsFileService.sendFilesToAppGroups(data);
  }
  return LiveActivitiesPlatform.instance.createActivity(
    activityId,
    data,
    removeWhenAppIsKilled: removeWhenAppIsKilled,
    staleIn: staleIn,
  );
}