istornz/flutter_live_activities

Multiple notifications support broke the library usage for single notifications

ggirotto opened this issue ยท 4 comments

The new multiple notifications addition (https://pub.dev/packages/live_activities#multiple-notifications-) broke the app for single notification usage. The step of getting the notification from user defaults now fail if the key prefix implementation is not added.

Hey,
This was something I mentioned to @istornz in my PR that added multi notification support.
You will need to make use of the prefix even for single notifications now.
I am open to other solutions that would allow both single and multiple life activities at the same time without a clash in the sharedDefault .

The project's readme also includes a section regarding the new usage of the sharedDefaults.

image

Tl; DR;

To migrate from 1.8.x -> 1.9.x:

  1. Add the new extension to the end of your file or as a new file you want to import:
extension LiveActivitiesAppAttributes {
  func prefixedKey(_ key: String) -> String {
    return "\(id)_\(key)"
  }
}
  1. Replace all access to the sharedDefault with the prefixed version:
ActivityConfiguration(for: LiveActivitiesAppAttributes.self) { context in
   ...
  // old
  let matchName = sharedDefault.string(forKey: "matchName")!

  // new
  let matchName = sharedDefault.string(forKey: context.attributes.prefixedKey("matchName"))!
   ...

Hi @ggirotto !
As @Clon1998 said, now you need to add a prefix even for single notification. I updated README.md file & put the 1.9.0 release as Breaking Changes.

If we found an another solution I will remove the dependence of prefix for single based notification ๐Ÿ‘

Hey guys,

Sorry, that was my bad. I didn't pay attention to README and CHANGELOG before creating this ticket. The steps are well described there. Thanks for the answers!