diff --git a/.cirrus.yml b/.cirrus.yml index f16443138..f450f78de 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,4 +1,5 @@ -build_example_android_task: +task: + name: Build Android example app container: image: cirrusci/flutter:stable pub_cache: @@ -7,7 +8,8 @@ build_example_android_task: - cd flutter_local_notifications/example - flutter build apk --debug -build_example_ios_task: +task: + name: Build iOS example app osx_instance: image: catalina-flutter pub_cache: @@ -16,14 +18,16 @@ build_example_ios_task: - cd flutter_local_notifications/example - flutter build ios --no-codesign --debug -test_platform_interface_task: +task: + name: Run platform interface tests container: image: cirrusci/flutter:stable test_script: - cd flutter_local_notifications_platform_interface - flutter test -test_plugin_task: +task: + name: Run plugin unit tests container: image: cirrusci/flutter:stable pub_cache: diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index c31cc801a..babe76017 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,3 +1,12 @@ +# [1.2.0] + +* Added the `resolvePlatformSpecificImplementation()` method to the `FlutterLocalNotificationsPlugin` class. This can be used to resolve the underlying platform implementation in order to access platform-specific APIs. +* **BREAKING CHANGE* the static `instance` properties in the `IOSFlutterLocalNotificationsPlugin` and `AndroidFlutterLocalNotificationsPlugin` classes have been removed due to addition of the `resolvePlatformSpecificImplementation()` +* Updated readme to remove use of `new` keyword in code snippets +* Bumped e2e dependency +* Bumped example app dependencies +* Make the pedantic dev_dependency explicit + # [1.1.7+1] * Minor update to readme on description around requesting notification permissions diff --git a/flutter_local_notifications/README.md b/flutter_local_notifications/README.md index 1ce244269..37e797fae 100644 --- a/flutter_local_notifications/README.md +++ b/flutter_local_notifications/README.md @@ -70,10 +70,9 @@ The GitHub repository has an example app that should demonstrate of all the supp The following samples will demonstrate the more commonly used functionalities. The first step is to create a new instance of the plugin class and then initialise it with the settings to use for each platform ```dart -FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); +FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project -var initializationSettingsAndroid = - new AndroidInitializationSettings('app_icon'); +var initializationSettingsAndroid = AndroidInitializationSettings('app_icon'); var initializationSettingsIOS = IOSInitializationSettings( onDidReceiveLocalNotification: onDidReceiveLocalNotification); var initializationSettings = InitializationSettings( @@ -91,7 +90,7 @@ Future onSelectNotification(String payload) async { } await Navigator.push( context, - new MaterialPageRoute(builder: (context) => new SecondScreen(payload)), + MaterialPageRoute(builder: (context) => SecondScreen(payload)), ); } ``` @@ -108,19 +107,19 @@ By default this plugin will request notification permissions when it is initiali 1. `requestAlertPermission` that control this behaviour. -If you want to request permissions at a later point in your application, set all of the above to false. +If you want to request permissions at a later point in your application on iOS, set all of the above to false. ```dart -FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); +FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); var initializationSettingsAndroid = - new AndroidInitializationSettings('app_icon'); -var initializationSettingsIOS = new IOSInitializationSettings( + AndroidInitializationSettings('app_icon'); +var initializationSettingsIOS = IOSInitializationSettings( requestSoundPermission: false, requestBadgePermission: false, requestAlertPermission: false, onDidReceiveLocalNotification: onDidReceiveLocalNotification, ); -var initializationSettings = new InitializationSettings( +var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification); @@ -129,13 +128,18 @@ await flutterLocalNotificationsPlugin.initialize(initializationSettings, Then call `requestPermissions` method with desired permissions at the appropriate point in your application ```dart -var result = await IOSFlutterLocalNotificationsPlugin.instance?.requestPermissions( - sound: true, - badge: true, - alert: true, - ); +var result = await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: true, + badge: true, + sound: true, + ); ``` +Here the call to `flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()` returns the iOS implementation of the plugin that contains APIs specific to iOS, provided that the application is running on iOS. The `?.` operator is used here as the result will be null when run on other platforms. Developers may alternative choose to guard this call by checking the platform their application is running on. + ### Displaying a notification ```dart @@ -156,13 +160,13 @@ In this block of code, the details for each platform have been specified. This i ```dart var scheduledNotificationDateTime = - new DateTime.now().add(new Duration(seconds: 5)); + DateTime.now().add(Duration(seconds: 5)); var androidPlatformChannelSpecifics = - new AndroidNotificationDetails('your other channel id', + AndroidNotificationDetails('your other channel id', 'your other channel name', 'your other channel description'); var iOSPlatformChannelSpecifics = - new IOSNotificationDetails(); -NotificationDetails platformChannelSpecifics = new NotificationDetails( + IOSNotificationDetails(); +NotificationDetails platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.schedule( 0, @@ -179,11 +183,11 @@ Note that on Android devices, the default behaviour is that the notification may ```dart // Show a notification every minute with the first appearance happening a minute after invoking the method var androidPlatformChannelSpecifics = - new AndroidNotificationDetails('repeating channel id', + AndroidNotificationDetails('repeating channel id', 'repeating channel name', 'repeating description'); var iOSPlatformChannelSpecifics = - new IOSNotificationDetails(); -var platformChannelSpecifics = new NotificationDetails( + IOSNotificationDetails(); +var platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.periodicallyShow(0, 'repeating title', 'repeating body', RepeatInterval.EveryMinute, platformChannelSpecifics); @@ -192,13 +196,13 @@ await flutterLocalNotificationsPlugin.periodicallyShow(0, 'repeating title', ### Show a daily notification at a specific time ```dart -var time = new Time(10, 0, 0); +var time = Time(10, 0, 0); var androidPlatformChannelSpecifics = - new AndroidNotificationDetails('repeatDailyAtTime channel id', + AndroidNotificationDetails('repeatDailyAtTime channel id', 'repeatDailyAtTime channel name', 'repeatDailyAtTime description'); var iOSPlatformChannelSpecifics = - new IOSNotificationDetails(); -var platformChannelSpecifics = new NotificationDetails( + IOSNotificationDetails(); +var platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.showDailyAtTime( 0, @@ -211,13 +215,13 @@ await flutterLocalNotificationsPlugin.showDailyAtTime( ### Show a weekly notification on specific day and time ```dart -var time = new Time(10, 0, 0); +var time = Time(10, 0, 0); var androidPlatformChannelSpecifics = - new AndroidNotificationDetails('show weekly channel id', + AndroidNotificationDetails('show weekly channel id', 'show weekly channel name', 'show weekly description'); var iOSPlatformChannelSpecifics = - new IOSNotificationDetails(); -var platformChannelSpecifics = new NotificationDetails( + IOSNotificationDetails(); +var platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime( 0, @@ -247,23 +251,23 @@ String groupChannelName = 'grouped channel name'; String groupChannelDescription = 'grouped channel description'; // example based on https://developer.android.com/training/notify-user/group.html AndroidNotificationDetails firstNotificationAndroidSpecifics = - new AndroidNotificationDetails( + AndroidNotificationDetails( groupChannelId, groupChannelName, groupChannelDescription, importance: Importance.Max, priority: Priority.High, groupKey: groupKey); NotificationDetails firstNotificationPlatformSpecifics = - new NotificationDetails(firstNotificationAndroidSpecifics, null); + NotificationDetails(firstNotificationAndroidSpecifics, null); await flutterLocalNotificationsPlugin.show(1, 'Alex Faarborg', 'You will not believe...', firstNotificationPlatformSpecifics); AndroidNotificationDetails secondNotificationAndroidSpecifics = - new AndroidNotificationDetails( + AndroidNotificationDetails( groupChannelId, groupChannelName, groupChannelDescription, importance: Importance.Max, priority: Priority.High, groupKey: groupKey); NotificationDetails secondNotificationPlatformSpecifics = - new NotificationDetails(secondNotificationAndroidSpecifics, null); + NotificationDetails(secondNotificationAndroidSpecifics, null); await flutterLocalNotificationsPlugin.show( 2, 'Jeff Chang', @@ -271,22 +275,22 @@ await flutterLocalNotificationsPlugin.show( secondNotificationPlatformSpecifics); // create the summary notification required for older devices that pre-date Android 7.0 (API level 24) -List lines = new List(); +List lines = List(); lines.add('Alex Faarborg Check this out'); lines.add('Jeff Chang Launch Party'); -InboxStyleInformation inboxStyleInformation = new InboxStyleInformation( +InboxStyleInformation inboxStyleInformation = InboxStyleInformation( lines, contentTitle: '2 new messages', summaryText: 'janedoe@example.com'); AndroidNotificationDetails androidPlatformChannelSpecifics = - new AndroidNotificationDetails( + AndroidNotificationDetails( groupChannelId, groupChannelName, groupChannelDescription, style: NotificationStyleAndroid.Inbox, styleInformation: inboxStyleInformation, groupKey: groupKey, setAsGroupSummary: true); NotificationDetails platformChannelSpecifics = - new NotificationDetails(androidPlatformChannelSpecifics, null); + NotificationDetails(androidPlatformChannelSpecifics, null); await flutterLocalNotificationsPlugin.show( 3, 'Attention', 'Two new messages', platformChannelSpecifics); ``` @@ -389,10 +393,10 @@ By design, iOS applications do not display notifications when they're in the for ```dart // initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project var initializationSettingsAndroid = - new AndroidInitializationSettings('app_icon'); -var initializationSettingsIOS = new IOSInitializationSettings( + AndroidInitializationSettings('app_icon'); +var initializationSettingsIOS = IOSInitializationSettings( onDidReceiveLocalNotification: onDidReceiveLocalNotification); -var initializationSettings = new InitializationSettings( +var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification); @@ -404,19 +408,19 @@ flutterLocalNotificationsPlugin.initialize(initializationSettings, // display a dialog with the notification details, tap ok to go to another page showDialog( context: context, - builder: (BuildContext context) => new CupertinoAlertDialog( - title: new Text(title), - content: new Text(body), + builder: (BuildContext context) => CupertinoAlertDialog( + title: Text(title), + content: Text(body), actions: [ CupertinoDialogAction( isDefaultAction: true, - child: new Text('Ok'), + child: Text('Ok'), onPressed: () async { Navigator.of(context, rootNavigator: true).pop(); await Navigator.push( context, - new MaterialPageRoute( - builder: (context) => new SecondScreen(payload), + MaterialPageRoute( + builder: (context) => SecondScreen(payload), ), ); }, diff --git a/flutter_local_notifications/analysis_options.yaml b/flutter_local_notifications/analysis_options.yaml index 815370ae1..b45d4fe03 100644 --- a/flutter_local_notifications/analysis_options.yaml +++ b/flutter_local_notifications/analysis_options.yaml @@ -1,6 +1 @@ -include: package:pedantic/analysis_options.1.8.0.yaml - -linter: - rules: - - camel_case_types - - unnecessary_new \ No newline at end of file +include: package:pedantic/analysis_options.1.8.0.yaml \ No newline at end of file diff --git a/flutter_local_notifications/example/lib/main.dart b/flutter_local_notifications/example/lib/main.dart index 7e35328f0..1ea200352 100644 --- a/flutter_local_notifications/example/lib/main.dart +++ b/flutter_local_notifications/example/lib/main.dart @@ -58,14 +58,13 @@ Future main() async { }); var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); - var initialised = await flutterLocalNotificationsPlugin.initialize( - initializationSettings, onSelectNotification: (String payload) async { + await flutterLocalNotificationsPlugin.initialize(initializationSettings, + onSelectNotification: (String payload) async { if (payload != null) { debugPrint('notification payload: ' + payload); } selectNotificationSubject.add(payload); }); - print('initialised: $initialised'); runApp( MaterialApp( home: HomePage(), @@ -105,13 +104,14 @@ class _HomePageState extends State { } void _requestIOSPermissions() { - if (Platform.isIOS) { - IOSFlutterLocalNotificationsPlugin.instance?.requestPermissions( - alert: true, - badge: true, - sound: true, - ); - } + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: true, + badge: true, + sound: true, + ); } void _configureDidReceiveLocalNotificationSubject() { diff --git a/flutter_local_notifications/example/pubspec.yaml b/flutter_local_notifications/example/pubspec.yaml index bfe4d7298..f7318f7f4 100644 --- a/flutter_local_notifications/example/pubspec.yaml +++ b/flutter_local_notifications/example/pubspec.yaml @@ -6,9 +6,9 @@ dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.3 - http: ^0.12.0+2 - path_provider: ^1.5.1 - shared_preferences: ^0.5.6 + http: ^0.12.0+4 + path_provider: ^1.6.1 + shared_preferences: ^0.5.6+2 rxdart: ^0.23.1 flutter_local_notifications: path: ../ @@ -18,7 +18,8 @@ dev_dependencies: sdk: flutter flutter_test: sdk: flutter - e2e: ^0.2.3 + e2e: ^0.2.4+2 + pedantic: ^1.8.0 flutter: uses-material-design: true diff --git a/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e.dart b/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e.dart new file mode 100644 index 000000000..270d40c9b --- /dev/null +++ b/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e.dart @@ -0,0 +1,40 @@ +import 'dart:io'; + +import 'package:e2e/e2e.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + E2EWidgetsFlutterBinding.ensureInitialized(); + FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; + + setUp(() async { + flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + final initializationSettingsAndroid = + AndroidInitializationSettings('app_icon'); + final initializationSettingsIOS = IOSInitializationSettings(); + final initializationSettings = InitializationSettings( + initializationSettingsAndroid, initializationSettingsIOS); + await flutterLocalNotificationsPlugin.initialize(initializationSettings); + }); + + testWidgets( + 'Can resolve platform-specific plugin implementation when run on appropriate platform', + (WidgetTester tester) async { + if (Platform.isIOS) { + expect( + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + .runtimeType, + IOSFlutterLocalNotificationsPlugin); + } else if (Platform.isAndroid) { + expect( + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + .runtimeType, + AndroidFlutterLocalNotificationsPlugin); + } + }); +} diff --git a/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e_test.dart b/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e_test.dart new file mode 100644 index 000000000..bcdc4f6f6 --- /dev/null +++ b/flutter_local_notifications/example/test_driver/flutter_local_notifications_e2e_test.dart @@ -0,0 +1,11 @@ +import 'dart:async'; +import 'dart:io'; +import 'package:flutter_driver/flutter_driver.dart'; + +Future main() async { + final FlutterDriver driver = await FlutterDriver.connect(); + final String result = + await driver.requestData(null, timeout: const Duration(minutes: 1)); + await driver.close(); + exit(result == 'pass' ? 0 : 1); +} diff --git a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart index ba164a8d8..29039353a 100644 --- a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart +++ b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart @@ -15,6 +15,9 @@ import 'types.dart'; /// /// The plugin will check the platform that is running on to use the appropriate platform-specific /// implementation of the plugin. The plugin methods will be a no-op when the platform can't be detected. +/// +/// Use [resolvePlatformSpecificImplementation] and pass the platform-specific type of the plugin to get the +/// underlying platform-specific implementation if access to platform-specific APIs are needed. class FlutterLocalNotificationsPlugin { factory FlutterLocalNotificationsPlugin() => _instance; @@ -44,6 +47,33 @@ class FlutterLocalNotificationsPlugin { final Platform _platform; + /// Returns the underlying platform-specific implementation of given type [T], which + /// must be the type of a concrete [FlutterLocalNotificationsPlatform] subclass. + /// + /// Requires running on the appropriate platform that matches the specified type for a result to be returned. + /// For example, when the specified type argument is of type [AndroidFlutterLocalNotificatiosPlugin], + /// this will only return a result of that type when running on Android. + T resolvePlatformSpecificImplementation< + T extends FlutterLocalNotificationsPlatform>() { + if (T == FlutterLocalNotificationsPlatform) { + throw ArgumentError.value(T, + 'The type argument must be a concrete subclass of FlutterLocalNotificationsPlatform'); + } + if (_platform.isAndroid && T == AndroidFlutterLocalNotificationsPlugin) { + if (FlutterLocalNotificationsPlatform.instance + is AndroidFlutterLocalNotificationsPlugin) { + return FlutterLocalNotificationsPlatform.instance; + } + } else if (_platform.isIOS && T == IOSFlutterLocalNotificationsPlugin) { + if (FlutterLocalNotificationsPlatform.instance + is IOSFlutterLocalNotificationsPlugin) { + return FlutterLocalNotificationsPlatform.instance; + } + } + + return null; + } + /// Initializes the plugin. /// /// Call this method on application before using the plugin further. This should only be done once. When a notification @@ -62,13 +92,13 @@ class FlutterLocalNotificationsPlugin { Future initialize(InitializationSettings initializationSettings, {SelectNotificationCallback onSelectNotification}) async { if (_platform.isAndroid) { - return await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + return await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.initialize(initializationSettings?.android, onSelectNotification: onSelectNotification); } else if (_platform.isIOS) { - return await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + return await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.initialize(initializationSettings?.ios, onSelectNotification: onSelectNotification); } @@ -82,12 +112,12 @@ class FlutterLocalNotificationsPlugin { /// used to launch the app. Future getNotificationAppLaunchDetails() async { if (_platform.isAndroid) { - return await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + return await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.getNotificationAppLaunchDetails(); } else if (_platform.isIOS) { - return await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + return await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.getNotificationAppLaunchDetails(); } else { return await FlutterLocalNotificationsPlatform.instance @@ -101,14 +131,14 @@ class FlutterLocalNotificationsPlugin { NotificationDetails notificationDetails, {String payload}) async { if (_platform.isAndroid) { - await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.show(id, title, body, notificationDetails: notificationDetails?.android, payload: payload); } else if (_platform.isIOS) { - await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.show(id, title, body, notificationDetails: notificationDetails?.iOS, payload: payload); } else { @@ -138,14 +168,14 @@ class FlutterLocalNotificationsPlugin { DateTime scheduledDate, NotificationDetails notificationDetails, {String payload, bool androidAllowWhileIdle = false}) async { if (_platform.isAndroid) { - await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) - ?.schedule( + await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + .schedule( id, title, body, scheduledDate, notificationDetails?.android, payload: payload, androidAllowWhileIdle: androidAllowWhileIdle); } else if (_platform.isIOS) { - await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.schedule(id, title, body, scheduledDate, notificationDetails?.iOS, payload: payload); } @@ -158,14 +188,14 @@ class FlutterLocalNotificationsPlugin { RepeatInterval repeatInterval, NotificationDetails notificationDetails, {String payload}) async { if (_platform.isAndroid) { - await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.periodicallyShow(id, title, body, repeatInterval, notificationDetails: notificationDetails?.android, payload: payload); } else if (_platform.isIOS) { - await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.periodicallyShow(id, title, body, repeatInterval, notificationDetails: notificationDetails?.iOS, payload: payload); } else { @@ -179,8 +209,8 @@ class FlutterLocalNotificationsPlugin { Time notificationTime, NotificationDetails notificationDetails, {String payload}) async { if (_platform.isAndroid) { - await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.showDailyAtTime( id, title, body, notificationTime, notificationDetails?.android, payload: payload); @@ -198,14 +228,14 @@ class FlutterLocalNotificationsPlugin { Day day, Time notificationTime, NotificationDetails notificationDetails, {String payload}) async { if (_platform.isAndroid) { - await (FlutterLocalNotificationsPlatform.instance - as AndroidFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() ?.showWeeklyAtDayAndTime(id, title, body, day, notificationTime, notificationDetails?.android, payload: payload); } else if (_platform.isIOS) { - await (FlutterLocalNotificationsPlatform.instance - as IOSFlutterLocalNotificationsPlugin) + await resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() ?.showWeeklyAtDayAndTime( id, title, body, day, notificationTime, notificationDetails?.iOS, payload: payload); diff --git a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart index a1ceea48a..e04cb1d12 100644 --- a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart +++ b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart @@ -54,15 +54,6 @@ class MethodChannelFlutterLocalNotificationsPlugin /// Android implementation of the local notifications plugin class AndroidFlutterLocalNotificationsPlugin extends MethodChannelFlutterLocalNotificationsPlugin { - /// Android specific plugin instance or null when not running in Android environment - static AndroidFlutterLocalNotificationsPlugin get instance { - if (FlutterLocalNotificationsPlatform.instance - is AndroidFlutterLocalNotificationsPlugin) { - return FlutterLocalNotificationsPlatform.instance; - } - return null; - } - SelectNotificationCallback _onSelectNotification; /// Initializes the plugin. Call this method on application before using the plugin further. @@ -182,15 +173,6 @@ class AndroidFlutterLocalNotificationsPlugin /// iOS implementation of the local notifications plugin class IOSFlutterLocalNotificationsPlugin extends MethodChannelFlutterLocalNotificationsPlugin { - /// IOS specific instance of plugin or null when not running in iOS environment - static IOSFlutterLocalNotificationsPlugin get instance { - if (FlutterLocalNotificationsPlatform.instance - is IOSFlutterLocalNotificationsPlugin) { - return FlutterLocalNotificationsPlatform.instance; - } - return null; - } - SelectNotificationCallback _onSelectNotification; DidReceiveLocalNotificationCallback _onDidReceiveLocalNotification; diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index d94125c1f..5fccf6d00 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform. -version: 1.1.7+1 +version: 1.2.0 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications dependencies: @@ -14,10 +14,10 @@ dev_dependencies: sdk: flutter flutter_test: sdk: flutter - e2e: ^0.2.3 + e2e: ^0.2.4+2 mockito: ^4.1.1 plugin_platform_interface: ^1.0.1 - + pedantic: ^1.8.0 flutter: plugin: