live_activities 1.3.0 copy "live_activities: ^1.3.0" to clipboard
live_activities: ^1.3.0 copied to clipboard

A Flutter plugin to use iOS 16.1+ Live Activities & iPhone 14 Pro Dynamic Island features

flutter ios 16 live activities

Live Activities #

A Flutter plugin to use iOS 16.1+ Live Activities & iPhone 14 Pro Dynamic Island features.


๐Ÿง What is it ? #

This plugin use iOS ActivityKit API.

live_activities can be used to show dynamic live notification & implement dynamic island feature on the iPhone 14 Pro / Max โšซ๏ธ

โš ๏ธ live_activities is only intended to use with iOS 16.1+ ! It will simply do nothing on other platform & < iOS 16.1

flutter ios 16 live activities preview dynamic island flutter ios 16 live activities preview action

๐Ÿ‘ป Getting started #

Due to some technical restriction, it's not currently possible to only use Flutter ๐Ÿซฃ.

You need to implement in your Flutter iOS project a Widget Extension & develop in Swift/Objective-C your own Live Activity / Dynamic Island design.

โ„น๏ธ You can check into the example repository for a full example app using Live Activities & Dynamic Island


  • ๐Ÿ“ฑ Native #

    • Create natively your Live Activity view tutorial, you can also create natively a Dynamic Island tutorial.

    • Enable push notification capabilities.

    enable push notification capabilities
    • Enable live activities for both your app & widget extension.
    enable live activity
    • Create App Group for both Runner & your widget extension.
    enable live activity
  • ๐Ÿ’™ Flutter #

    • Import the plugin.
    import 'package:live_activities/live_activities.dart';
    
    • Initialize the Plugin by passing the created App Group Id (created above).
    final _liveActivitiesPlugin = LiveActivities();
    _liveActivitiesPlugin.init(appGroupId: "YOUR_CREATED_APP_ID");
    
    • Create your dynamic activity.
    final Map<String, dynamic> activityModel = {
      'name': 'Margherita',
      'ingredient': 'tomato, mozzarella, basil',
      'quantity': 1,
    };
    
    _liveActivitiesPlugin.createActivity(activityModel.toMap());
    

    You can pass all type of data you want but keep it mind it should be compatible with UserDefaults


Communicate over Native ๐Ÿงต and Flutter ๐Ÿ’™ #

In order to pass some useful data between your native live activity / dynamic island with your Flutter app you just need to setup URL scheme.

  • Add a custom url scheme in Xcode by navigating to Runner > Runner > URL Types > URL Schemes
add url scheme xcode
  • In your Swift code, just create a new link and open to your custom URL Scheme
Link(destination: URL(string: "la://my.app/order?=123")!) { // Replace "la" with your scheme
  Text("See order")
}

โš ๏ธ Don't forget to put the URL Scheme you have typed in the previous step.

  • In your Flutter App, you just need to listen on the url scheme Scheme
_liveActivitiesPlugin.urlSchemeStream().listen((schemeData) {
  // do what do you want here ๐Ÿค—
});

๐Ÿ“˜ Documentation #

Name Description Returned value
.init() Initialize the Plugin by providing an App Group Id (see above) Future When the plugin is ready to create/update an activity
.createActivity() Create an iOS live activity String The activity identifier
.updateActivity() Update the live activity data by using the activityId provided Future When the activity was updated
.endActivity() End the live activity by using the activityId provided Future When the activity was ended
.getAllActivitiesIds() Get all activities ids created Future<List<String>> List of all activities ids
.endAllActivities() End all live activities of the app Future When all activities was ended
.areActivitiesEnabled() Check if live activities feature are supported & enabled Future<bool> Live activities supported or not
.getActivityState() Get the activity current state Future<LiveActivityState> An enum to know the status of the activity (active, dismissed or ended)
.urlSchemeStream() Subscription to handle every url scheme (ex: when the app is opened from a live activity / dynamic island button, you can pass data) Future<UrlSchemeData> Url scheme data which handle scheme url host path queryItems

๐Ÿ‘ฅ Contributions #

Contributions are welcome. Contribute by creating a PR or create an issue ๐ŸŽ‰.

๐ŸŽฏ Roadmap #

  • โŒ Inject a Widget inside the notification with Flutter Engine ?
  • โŒ Pass media between extension & Flutter app.
  • โœ… Support multiple type instead of String (Date, Number etc.).
  • โœ… Pass data across native dynamic island and Flutter app.
  • โœ… Pass data across native live activity notification and Flutter app.
  • โœ… Cancel all activities.
  • โœ… Get all activities ids.
  • โœ… Check if live activities are supported.
378
likes
0
pub points
93%
popularity

Publisher

verified publisherdimitridessus.fr

A Flutter plugin to use iOS 16.1+ Live Activities & iPhone 14 Pro Dynamic Island features

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on live_activities