Skip to content

Commit d1cd8f2

Browse files
[flutter_local_notifications] Linux support (#1208)
* Initial Linux support * Add .gitignore * [Linux] Refactor details structure; prepare for dbus * [Linux] Move to separate package; init DBus implementation * [Linux] Base plugin implementation * [Linux] Add tests * [Linux] Add other spec hints * [Linux] Handle notification opening * [Linux] Implement notify server capabilities * [Linux] Add custom hints * [Linux] Fix TODO comments * [Linux] Fix hint values generic type * [Linux] Write example * Update README * [Linux] Update example and README * Update .cirrus.yml * [Linux] Add getSystemIdMap method * Update main repo README * [Linux] Add note for getSystemIdMap in documentation * Fix font size in example * Typo fix * Using private constructor for LinuxNotificationManager * Delete all abstract classes * Fix grammar
1 parent fc42fc9 commit d1cd8f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4384
-112
lines changed

.cirrus.yml

+24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ task:
3636
- cd flutter_local_notifications/example
3737
- flutter build macos
3838

39+
task:
40+
name: Build Linux example app
41+
container:
42+
image: cirrusci/flutter:dev
43+
pub_cache:
44+
folder: ~/.pub-cache
45+
setup_script:
46+
- apt update
47+
- apt install cmake ninja-build clang pkg-config libgtk-3-dev -y
48+
- flutter config --enable-linux-desktop
49+
build_script:
50+
- cd flutter_local_notifications/example
51+
- flutter build linux
52+
3953
task:
4054
name: Run platform interface tests
4155
container:
@@ -77,3 +91,13 @@ task:
7791
- cd flutter_local_notifications
7892
- cd example
7993
- flutter drive --driver=test_driver/integration_test.dart --target=integration_test/flutter_local_notifications_test.dart
94+
95+
task:
96+
name: Run Linux plugin tests
97+
container:
98+
image: cirrusci/flutter:stable
99+
pub_cache:
100+
folder: ~/.pub-cache
101+
test_script:
102+
- cd flutter_local_notifications_linux
103+
- flutter test

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This repository consists hosts the following packages
44

55
- [`flutter_local_notifications`](https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications): code for the cross-platform facing plugin used to display local notifications within Flutter applications
66
- [`flutter_local_notifications_platform_interface`](https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications_platform_interface): the code for the common platform interface
7+
- [`flutter_local_notifications_linux`](https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications_linux): the Linux implementation of [`flutter_local_notifications`](https://pub.dev/packages/flutter_local_notifications).
78

89
These can be found in the corresponding directories within the same name. Most developers are likely here as they are looking to use the `flutter_local_notifications` plugin. There is a readme file within each directory with more information.
910

flutter_local_notifications/README.md

+27-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![pub package](https://img.shields.io/pub/v/flutter_local_notifications.svg)](https://pub.dartlang.org/packages/flutter_local_notifications)
44
[![Build Status](https://api.cirrus-ci.com/github/MaikuB/flutter_local_notifications.svg)](https://cirrus-ci.com/github/MaikuB/flutter_local_notifications/master)
55

6-
A cross platform plugin for displaying local notifications.
6+
A cross platform plugin for displaying local notifications.
77

88
## Table of contents
99
- **[📱 Supported platforms](#-supported-platforms)**
@@ -16,6 +16,7 @@ A cross platform plugin for displaying local notifications.
1616
- [Updating application badge](#updating-application-badge)
1717
- [Custom notification sounds](#custom-notification-sounds)
1818
- [macOS differences](#macos-differences)
19+
- [Linux limitations](#Linux-limitations)
1920
- **[📷 Screenshots](#-screenshots)**
2021
- **[👏 Acknowledgements](#-acknowledgements)**
2122
- **[⚙️ Android Setup](#️-android-setup)**
@@ -47,6 +48,7 @@ A cross platform plugin for displaying local notifications.
4748
* **Android 4.1+**. Uses the [NotificationCompat APIs](https://developer.android.com/reference/androidx/core/app/NotificationCompat) so it can be run older Android devices
4849
* **iOS 8.0+**. On iOS versions older than 10, the plugin will use the UILocalNotification APIs. The [UserNotification APIs](https://developer.apple.com/documentation/usernotifications) (aka the User Notifications Framework) is used on iOS 10 or newer.
4950
* **macOS 10.11+**. On macOS versions older than 10.14, the plugin will use the [NSUserNotification APIs](https://developer.apple.com/documentation/foundation/nsusernotification). The [UserNotification APIs](https://developer.apple.com/documentation/usernotifications) (aka the User Notifications Framework) is used on macOS 10.14 or newer.
51+
* **Linux**. Uses the [Desktop Notifications Specification](https://developer.gnome.org/notification-spec/).
5052

5153
## ✨ Features
5254

@@ -83,6 +85,14 @@ A cross platform plugin for displaying local notifications.
8385
* [Android] Full-screen intent notifications
8486
* [iOS (all supported versions) & macOS 10.14+] Request notification permissions and customise the permissions being requested around displaying notifications
8587
* [iOS 10 or newer and macOS 10.14 or newer] Display notifications with attachments
88+
* [Linux] Ability to to use themed/Flutter Assets icons and sound
89+
* [Linux] Ability to to set the category
90+
* [Linux] Configuring the urgency
91+
* [Linux] Configuring the timeout (depends on system implementation)
92+
* [Linux] Ability to set custom notification location (depends on system implementation)
93+
* [Linux] Ability to set custom hints
94+
* [Linux] Ability to suppress sound
95+
* [Linux] Resident and transient notifications
8696

8797
## ⚠ Caveats and limitations
8898
The cross-platform facing API exposed by the `FlutterLocalNotificationsPlugin` class doesn't expose platform-specific methods as its goal is to provide an abstraction for all platforms. As such, platform-specific configuration is passed in as data. There are platform-specific implementations of the plugin that can be obtained by calling the [`resolvePlatformSpecificImplementation`](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/FlutterLocalNotificationsPlugin/resolvePlatformSpecificImplementation.html). An example of using this is provided in the section on requesting permissions on iOS. In spite of this, there may still be gaps that don't cover your use case and don't make sense to add as they don't fit with the plugin's architecture or goals. Developers can fork or maintain their own code for showing notifications in these situations.
@@ -114,13 +124,22 @@ Due to limitations currently within the macOS Flutter engine, `getNotificationAp
114124

115125
The `schedule`, `showDailyAtTime` and `showWeeklyAtDayAndTime` methods that were implemented before macOS support was added and have been marked as deprecated aren't implemented on macOS.
116126

127+
##### Linux limitations
128+
129+
Capabilities depend on the system notification server implementation, therefore, not all features listed in `LinuxNotificationDetails` may be supported. One of the ways to check some capabilities is to call the `LinuxFlutterLocalNotificationsPlugin.getCapabilities()` method.
130+
131+
Scheduled/pending notifications is currently not supported due to the lack of a scheduler API.
132+
133+
To respond to notification after the application is terminated, your application should be registered as DBus activatable (see [DBusApplicationLaunching](https://wiki.gnome.org/HowDoI/DBusApplicationLaunching) for more information), and register action before activating the application. This is difficult to do in a plugin because plugins instantiate during application activation, so `getNotificationAppLaunchDetails` can't be implemented without changing the main user application.
134+
117135
## 📷 Screenshots
118136

119137
| Platform | Screenshot |
120138
| ------------- | ------------- |
121139
| Android | <img height="480" src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/android_notification.png"> |
122140
| iOS | <img height="414" src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/ios_notification.png"> |
123141
| macOS | <img src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/macos_notification.png"> |
142+
| Linux | <img src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/gnome_linux_notification.png"> <img src="https://github.com/MaikuB/flutter_local_notifications/raw/master/images/kde_linux_notification.png"> |
124143

125144

126145
## 👏 Acknowledgements
@@ -199,7 +218,7 @@ By design, iOS applications *do not* display notifications while the app is in t
199218

200219
For iOS 10+, use the presentation options to control the behaviour for when a notification is triggered while the app is in the foreground. The default settings of the plugin will configure these such that a notification will be displayed when the app is in the foreground.
201220

202-
For older versions of iOS, you need to handle the callback as part of specifying the method that should be fired to the `onDidReceiveLocalNotification` argument when creating an instance `IOSInitializationSettings` object that is passed to the function for initializing the plugin.
221+
For older versions of iOS, you need to handle the callback as part of specifying the method that should be fired to the `onDidReceiveLocalNotification` argument when creating an instance `IOSInitializationSettings` object that is passed to the function for initializing the plugin.
203222

204223
Here is an example:
205224

@@ -259,7 +278,7 @@ The [`example`](https://github.com/MaikuB/flutter_local_notifications/tree/maste
259278

260279
### API reference
261280

262-
Checkout the lovely [API documentation](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/flutter_local_notifications-library.html) generated by pub.
281+
Checkout the lovely [API documentation](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/flutter_local_notifications-library.html) generated by pub.
263282

264283

265284
## Initialisation
@@ -412,7 +431,7 @@ tz.initializeTimeZones();
412431
Once the time zone database has been initialised, developers may optionally want to set a default local location/time zone
413432

414433
```dart
415-
tz.setLocalLocation(tz.getLocation(timeZoneName));
434+
tz.setLocalLocation(tz.getLocation(timeZoneName));
416435
```
417436

418437
The `timezone` package doesn't provide a way to obtain the current time zone on the device so developers will need to use [platform channels](https://flutter.dev/docs/development/platform-integration/platform-channels) or use other packages that may be able to provide the information. The example app uses the [`flutter_native_timezone`](https://pub.dev/packages/flutter_native_timezone) plugin.
@@ -587,11 +606,11 @@ if(!UserDefaults.standard.bool(forKey: "Notification")) {
587606

588607
## 📈 Testing
589608

590-
As the plugin class is not static, it is possible to mock and verify its behaviour when writing tests as part of your application.
591-
Check the source code for a sample test suite that has been kindly implemented (_test/flutter_local_notifications_test.dart_) that demonstrates how this can be done.
609+
As the plugin class is not static, it is possible to mock and verify its behaviour when writing tests as part of your application.
610+
Check the source code for a sample test suite that has been kindly implemented (_test/flutter_local_notifications_test.dart_) that demonstrates how this can be done.
592611

593-
If you decide to use the plugin class directly as part of your tests, the methods will be mostly no-op and methods that return data will return default values.
612+
If you decide to use the plugin class directly as part of your tests, the methods will be mostly no-op and methods that return data will return default values.
594613

595-
Part of this is because the plugin detects if you're running on a supported plugin to determine which platform implementation of the plugin should be used. If the platform isn't supported, it will default to the aforementioned behaviour to reduce friction when writing tests. If this not desired then consider using mocks.
614+
Part of this is because the plugin detects if you're running on a supported plugin to determine which platform implementation of the plugin should be used. If the platform isn't supported, it will default to the aforementioned behaviour to reduce friction when writing tests. If this not desired then consider using mocks.
596615

597616
If a platform-specific implementation of the plugin is required for your tests, a [named constructor](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/FlutterLocalNotificationsPlugin/FlutterLocalNotificationsPlugin.private.html) is available that allows you to specify the platform required e.g. a [`FakePlatform`](https://api.flutter.dev/flutter/package-platform_platform/FakePlatform-class.html).
Loading

0 commit comments

Comments
 (0)