You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here are the relevant parts of the current API I'm looking to change
details are defined in an implementation-specific package and are completely unrelated between platforms
there is a platform plugin abstract class defined in its own package
each platform implements their plugin in a separate package
each plugin expects its own details
At launch, the platform plugin, if there is one, registers itself as FlutterLocalNotificationsPlatform.instance
the main plugin defines a "collection of details"
the main plugin defines a "master plugin" that uses the correct details in the correct plugin
The key point of this issue is that there is no way to abstract over any of this. Since all the details types are completely unrelated, each plugin must override each FlutterLocalNotificationsPlatform method to accept its own version of the details, and the master plugin must also override each one to supply the platform implementation with the correct details. In other words, we get a lot of functions like
Future<void> show(...) {
if (defaultTargetPlatform ==TargetPlatform.android && ...) {
// call resolve() with details.android
} elseif (defaultTargetPlatform ==TargetPlatform.ios && ...) {
// call resolve() with details.ios
} elseif (...) {
// and so on
}
}
This class alone takes up 500 lines of code and is full of runtime checks. I believe there's a better way:
In the platform_interface package:
declare a base class for all details, DetailsBase
declare a "collection of details", DetailsCollectionBase, with T? forPlatform<T extends DetailsBase>()
declare a base class for all plugins, PluginBase that uses DetailsCollectionBase when needed
This would all be non-breaking, but a lot more code can be saved by making a slightly breaking change: moving all platform-specific parameters into their respective PlatformNotificationDetails or lifting them to the platform interface. For example, .cancel(int id, {String? tag}) uses a tag parameter, and then specifically has to check whether to pass it (Linux) or not (otherwise). If all platforms accepted a tag parameter, this could be avoided. Similarly, zonedSchedule has an extra required parameter, androidScheduleMode, whereas that should maybe be an optional parameter on AndroidNotificationDetails with a reasonable default, like .exact.
@MaikuB What do you think? I'm in the middle of adding web support and I noticed a pattern like this would help reduce new code to the main package, and possibly some other boilerplate code as well, like the initialization settings. Feel free to pop any of these code samples into an IDE, they should have no analysis issues. Of course, I'll take care of the PR.
The text was updated successfully, but these errors were encountered:
Here are the relevant parts of the current API I'm looking to change
FlutterLocalNotificationsPlatform.instance
The key point of this issue is that there is no way to abstract over any of this. Since all the details types are completely unrelated, each plugin must override each
FlutterLocalNotificationsPlatform
method to accept its own version of the details, and the master plugin must also override each one to supply the platform implementation with the correct details. In other words, we get a lot of functions likeThis class alone takes up 500 lines of code and is full of runtime checks. I believe there's a better way:
In the
platform_interface
package:DetailsBase
DetailsCollectionBase
, withT? forPlatform<T extends DetailsBase>()
PluginBase
that usesDetailsCollectionBase
when neededImplementation of the platform interface
In each platform's implementation/package:
DetailsBase
with that platform's detailsPluginBase
and implement all the methodsExample of an Android implementation
In the main package:
DetailsCollectionBase
with a member for each platform, likeNotificationDetails
Plugin
by forwarding all methods toPluginBase
PluginBase.instance
for end-users directlyImplementation of the main package
This would all be non-breaking, but a lot more code can be saved by making a slightly breaking change: moving all platform-specific parameters into their respective
PlatformNotificationDetails
or lifting them to the platform interface. For example,.cancel(int id, {String? tag})
uses a tag parameter, and then specifically has to check whether to pass it (Linux) or not (otherwise). If all platforms accepted atag
parameter, this could be avoided. Similarly,zonedSchedule
has an extra required parameter,androidScheduleMode
, whereas that should maybe be an optional parameter onAndroidNotificationDetails
with a reasonable default, like.exact
.@MaikuB What do you think? I'm in the middle of adding web support and I noticed a pattern like this would help reduce new code to the main package, and possibly some other boilerplate code as well, like the initialization settings. Feel free to pop any of these code samples into an IDE, they should have no analysis issues. Of course, I'll take care of the PR.
The text was updated successfully, but these errors were encountered: