mitchhymel / local_notifications Goto Github PK
View Code? Open in Web Editor NEWNo longer in development -Flutter plugin for creating notifications
License: BSD 2-Clause "Simplified" License
No longer in development -Flutter plugin for creating notifications
License: BSD 2-Clause "Simplified" License
After adding this plugin to an application I'm building, my travis jobs started to fail:
https://travis-ci.org/CrochetLand/app/jobs/369895016
It looks like something related to this: flutter/flutter#10068
Any idea if this is realted to this plugin?
I filed myself a bug to keep track of it :-)
Since notification from server didn't have PRESENT_WHILE_APP_OPEN_KEY column
public func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent: UNNotification,
withCompletionHandler: @escaping (UNNotificationPresentationOptions)->()) {
let showNotificationWhileAppOpen = willPresent.request.content.userInfo[SwiftLocalNotificationsPlugin.PRESENT_WHILE_APP_OPEN_KEY] as! Bool
if (showNotificationWhileAppOpen) {
withCompletionHandler([.alert, .sound, .badge])
}
}
Hi for a project at school i got the task to add push notifications to our app. i'm a pretty big noob so i was relieved when i saw your app, running it on its own is just fine, but when i try to intergrate it into my app the notifications don't show up and i think i know what the problem is in the manifest you have this line
for you the entire line is green when i look into your project but in my project the part starting at sercives is red so that includes services. I might be installing it wrong but i moved all the .dart files you had to my lib folder and imported it and when i write code i don't get errors so that went well. but when i press the button the notification just won't show up. could you maybe help me out? I would really appreciate it.
Creating this issue to track work to add support for custom sound to play when the notification is delivered.
Hi , i am getting below errors while building the flutter project after adding this lib.
import android.support.v4.app.NotificationCompat; [ ] ^ [ ] symbol: class NotificationCompat [ ] location: package android.support.v4.app [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:42: error: package NotificationCompat does not exist [ ] private void setVibratePattern(NotificationCompat.Builder builder, NotificationSettings settings) { [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:50: error: package NotificationCompat does not exist [ ] private void addActions(NotificationCompat.Builder builder, NotificationSettings settings, [ ] ^ [ +1 ms] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:60: error: package NotificationCompat does not exist [ ] private void setTicker(NotificationCompat.Builder builder, NotificationSettings settings) { [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:65: error: package NotificationCompat does not exist [ ] private void setLargeIcon(NotificationCompat.Builder builder, NotificationSettings settings) { [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/LocalNotificationsPlugin.java:5: error: cannot find symbol [ ] import android.support.v4.app.NotificationManagerCompat; [ ] ^ [ ] symbol: class NotificationManagerCompat [ ] location: package android.support.v4.app [ +93 ms] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/LocalNotificationsPlugin.java:160: error: cannot find symbol [ ] private NotificationManagerCompat getNotificationManagerCompat() { [ ] ^ [ ] symbol: class NotificationManagerCompat [ ] location: class LocalNotificationsPlugin [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/GenerateLocalNotificationsTask.java:8: error: cannot find symbol [ ] import android.support.v4.app.NotificationManagerCompat; [ ] ^ [ ] symbol: class NotificationManagerCompat [ ] location: package android.support.v4.app [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/GenerateLocalNotificationsTask.java:66: error: cannot find symbol [ ] private NotificationManagerCompat getNotificationCompatManager() { [ ] ^ [ ] symbol: class NotificationManagerCompat [ ] location: class GenerateLocalNotificationsTask [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:24: error: package NotificationCompat does not exist [ ] NotificationCompat.Builder builder = new NotificationCompat.Builder(context, settings.Channel) [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:24: error: package NotificationCompat does not exist [ ] NotificationCompat.Builder builder = new NotificationCompat.Builder(context, settings.Channel) [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:54: error: package NotificationCompat does not exist [ ] NotificationCompat.Action action = new NotificationCompat.Action [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/factories/NotificationFactory.java:55: error: package NotificationCompat.Action does not exist [ ] .Builder(0, extraAction.actionText, intent).build(); [ ] ^ [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/LocalNotificationsPlugin.java:129: error: cannot find symbol [ ] NotificationManagerCompat notificationManager = getNotificationManagerCompat(); [ ] ^ [ +4 ms] symbol: class NotificationManagerCompat [ ] location: class LocalNotificationsPlugin [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/LocalNotificationsPlugin.java:161: error: cannot find symbol [ ] return NotificationManagerCompat.from(getActiveContext()); [ ] ^ [ ] symbol: variable NotificationManagerCompat [ ] location: class LocalNotificationsPlugin [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/GenerateLocalNotificationsTask.java:56: error: cannot find symbol [ ] NotificationManagerCompat notificationManager = getNotificationCompatManager(); [ ] ^ [ ] symbol: class NotificationManagerCompat [ ] location: class GenerateLocalNotificationsTask [ ] /home/signity/.pub-cache/hosted/pub.dartlang.org/local_notifications-0.0.7/android/src/main/java/com/mythichelm/localnotifications/GenerateLocalNotificationsTask.java:67: error: cannot find symbol [ ] return NotificationManagerCompat.from(this.mContext.get()); [ ] ^ [ ] symbol: variable NotificationManagerCompat [ ] location: class GenerateLocalNotificationsTask [ ] 17 errors [ +89 ms] FAILURE: Build failed with an exception. [ ] * What went wrong: [ ] Execution failed for task ':local_notifications:compileDebugJavaWithJavac'. [ ] > Compilation failed; see the compiler error output for details. [ ] * Try: [ ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. [ ] * Get more help at https://help.gradle.org [ ] BUILD FAILED in 1m 8s [{"event":"app.progress","params":{"appId":"620c3a74-3727-41ea-a6ac-98dca5654549","id":"2","progressId":null,"finished":true}}] [ +444 ms] ******************************************************************************************* [ ] The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app. [ ] See https://goo.gl/CP92wY for more information on the problem and how to fix it. [ ] *******************************************************************************************
i would like to use icons on actions instead of text
I run the sample code in the folder ,and I could see some buttons ,but when I click the 'Create basic notification' button , it just plays vibrate , I can see nothing displayed.
Hi Mitch,
Thank you so much for the plugin. Do you have an estimate for the ios version?
I wanted to know is it possible to call a function when user swipe notificaiton without pressing it ?
something smilar to onSelectNotification
.
I want to know if user pressed the notification or dissmissed it.
The app crashes when initializing and sending local notifications when it's built in release mode with the given configuration:
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
proguard-rules.pro
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
Disabling minifyEnabled rule fixes the issue. So seems like something is cut out of .apk that is needed for this plugin to work.
If needed I can provide the crash log once it shows up in the google play console.
I'm facing an issue when I want to create a new notification. The notification will be created, but the method throws an exception. Can you please look into this?
It even happens with the most basic usage:
LocalNotifications.createNotification( title: "Hello", content: "There" );
E/flutter ( 8948): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 8948): type '_Future' is not a subtype of type 'Future<int>' where
E/flutter ( 8948): _Future is from dart:async
E/flutter ( 8948): Future is from dart:async
E/flutter ( 8948): int is from dart:core
E/flutter ( 8948):
E/flutter ( 8948): #0 LocalNotifications.createNotification (package:local_notifications/local_notifications.dart:91:21)
notificationId = await LocalNotifications.createNotification(
title: 'Basic',
content: 'some basic notification',
// imageUrl: String
isOngoing: false,
onNotificationClick: new NotificationAction(
actionText: "some action",
payload: "some payload",
callback: removeNotify,
),
...
void removeNotify(String payload) {
LocalNotifications.removeNotification(notificationId);
}
Unable to get notification to disappear when clicked. On my personal phone (running Lollipop) they dismiss automatically. While the AVD I am running is v6 this behavior shouldn't be any different.
Step To Reproduce in iOS simulater:
══╡ EXCEPTION CAUGHT BY ANIMATION LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown while notifying status listeners for AnimationController:
flutter: Cannot reuse a MaterialPageRoute after disposing it.
flutter: 'package:flutter/src/widgets/routes.dart': Failed assertion: line 217 pos 12:
flutter: '!_transitionCompleter.isCompleted'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2 TransitionRoute.didPopNext (package:flutter/src/widgets/routes.dart:217:12)
flutter: #3 NavigatorState.pop (package:flutter/src/widgets/navigator.dart:1944:23)
flutter: #4 _CupertinoBackGestureController._handleStatusChanged (package:flutter/src/cupertino/route.dart:655:17)
flutter: #5 _AnimationController&Animation&AnimationEagerListenerMixin&AnimationLocalListenersMixin&AnimationLocalStatusListenersMixin.notifyStatusListeners (package:flutter/src/animation/listener_helpers.dart:192:19)
flutter: #6 AnimationController._checkStatusChanged (package:flutter/src/animation/animation_controller.dart:736:7)
flutter: #7 AnimationController._tick (package:flutter/src/animation/animation_controller.dart:752:5)
flutter: #8 Ticker._tick (package:flutter/src/scheduler/ticker.dart:228:5)
flutter: #9 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:988:15)
flutter: #10 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleBeginFrame. (package:flutter/src/scheduler/binding.dart:904:11)
flutter: #11 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:367:8)
flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:902:17)
flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:832:5)
flutter: #17 _invoke1 (dart:ui/hooks.dart:223:10)
flutter: #18 _beginFrame (dart:ui/hooks.dart:162:3)
flutter: (elided 5 frames from class _AssertionError and package dart:async)
flutter:
flutter: The AnimationController notifying status listeners was:
flutter: AnimationController#340eb(⏮ 0.000; paused; DISPOSED; for MaterialPageRoute(null))
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Hi, I tried to use the plugin for IOS. Its working fine in android app. In ios i get the below error. Do i need any set up for ios project to work.
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET local_notifications OF PROJECT Pods WITH CONFIGURATION Debug ===
:1:9: note: in file included from :1:
#import "Headers/local_notifications-umbrella.h"
^
/work/push_notification/ios/Pods/Target Support Files/local_notifications/local_notifications-umbrella.h:13:9: error: include of non-modular header inside framework module 'local_notifications': '.pub-cache/git/local_notifications-531e3ede54f58eb9a1bef2fb4d7a8d612d98ab1e/ios/Classes/LocalNotificationsPlugin.h'
#import "LocalNotificationsPlugin.h"
^
:0: error: could not build Objective-C module 'local_notifications'
Could not build the precompiled application for the device.
Creating this issue to track work to add support for custom vibration pattern on notification delivery.
Is it working like FCM?
`Launching lib/main.dart on iPhone XS in debug mode...
Starting Xcode build...
Xcode build done. 1.5s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET local_notifications OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/apanda/.pub-cache/hosted/pub.flutter-io.cn/local_notifications-0.0.7/ios/Classes/SwiftLocalNotificationsPlugin.swift:123:52: error: cannot call value of non-function type 'UNNotificationSound'
content.sound = UNNotificationSound.default()
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
`
how can i solve it .
I am unable to change notification Icon it is giving me errors whenever i am changing the imageUrl inside createNotification method . And can you plz tell me how can i make notification icons custom like images from files like in music player apps icon is the albumArt of the song
`import 'package:camera/camera.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:image_picker/image_picker.dart';
import 'package:Unify_Mobile/globals.dart' as globals;
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:local_notifications/local_notifications.dart';
Future openCamera(BuildContext context, bool photo) async {
cameras = await availableCameras();
if (photo) {
//Picture
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => new MyHomePage()),
);
} else {
//Video
}
}
List cameras;
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@OverRide
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State {
Future _imageFile;
Image uploadImage(File file) {
return new Image.file(file);
}
onNotificationClick(String payload) {
// // payload is "some payload"
// LocalNotifications.removeNotification(0);
print('Running in background and received payload: $payload');
}
void sendNotification(String title, String message, int id) async {
await LocalNotifications.createNotification(
title: title,
content: message,
id: id,
onNotificationClick: new NotificationAction(
actionText: "some action", // Note: only works for iOS
callback: onNotificationClick,
payload: "some payload"));
}
@OverRide
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: const Text('Capture'),
backgroundColor: Colors.white,
actions: [
new IconButton(
tooltip: 'Upload to Gallery',
icon: new Icon(
Icons.file_upload,
),
onPressed: () {
_imageFile == null
? globals.Utility.showAlertPopup(context, "Info", "Photo Required for Upload!", "")
: sendNotification(
"Upload Complete",
"Image has finished processing.",
0); //True for Stock Camera
},
),
],
),
body: new Center(
child: new FutureBuilder(
future: _imageFile,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.error == null) {
return new Image.file(snapshot.data);
} else if (snapshot.error != null) {
return const Text('error picking video.');
} else {
return const Text('You have not yet picked an video.');
}
})),
floatingActionButton: new FloatingActionButton(
onPressed: () {
setState(() {
_imageFile = ImagePicker.pickImage();
});
},
tooltip: 'Pick Video',
child: new Icon(Icons.add_a_photo),
),
);
}
}
`
When a notification appeared, the panel of it will disappeared after a few seconds. How to hold it?
Ran the example app on my Samsung S7 Edge with Android 8.0 (Oreo) and no notifications are sent.
With debug enabled, clicking the first buttons produces the following output, but no notifications appear:
D/ViewRootImpl@c829dcf[MainActivity]( 8413): ViewPostIme pointer 0
D/ViewRootImpl@c829dcf[MainActivity]( 8413): ViewPostIme pointer 1
I/flutter ( 8413): LocalNotificationsPlugin (Dart): Invoking "local_notifications_createNotification" with map="{title: Basic, content: some basic notification, imageUrl: , ticker: , id: 0, onNotificationClick: {callback: removeNotify, actionText: some action, payload: , launchesApp: true}, extraActions: [], androidSettings: {isOngoing: false, channel: default_notification11, priority: 1, vibratePattern: []}, iOSSettings: {presentWhileAppOpen: true}}"
D/LocalNotifications( 8413): (Android): In onMethodCall for method 'local_notifications_createNotification'
D/LocalNotifications( 8413): (Android): Creating NotificationSettings from arguments
D/LocalNotifications( 8413): (Android): Finished creating NotificationSettings from arguments
D/LocalNotifications( 8413): (Android): Starting GenerateLocalNotificationsTask
D/LocalNotifications( 8413): (Android): Creating Notification from settings: {"Body":"some basic notification","Channel":"default_notification11","ExtraActions":[],"Id":0,"ImageUrl":"","IsOngoing":false,"OnNotificationClick":{"actionText":"some action","callbackFunctionName":"removeNotify","launchesApp":true,"payload":""},"Priority":1,"Ticker":"","Title":"Basic","UseDefaultVibratePattern":true,"VibratePattern":[]}
D/LocalNotifications( 8413): (Android): Finished creating Notification from NotificationSettings
D/LocalNotifications( 8413): (Android): Calling NotificationManager.notify
D/Notification( 8413): allPendingIntents
Hello,
first of all, great job for making this plugin. However I am struggling with one use case I am trying to implement. I would like to create "progress notification". As I am coming from android enviroment, I know that android implementation is pretty straightforward.
https://medium.com/@britt.barak/notifications-part-2-progress-indicator-2aa4cdea24c6
I have not found a way how to achieve something like this in flutter using your plugin.
According to this SO question (and answers), it should be possible to do also on iOS using UIProgressBar, although I have very limited knowledge of iOS development and it may be off topic.
Here is my code:
static const AndroidNotificationChannel channel =
const AndroidNotificationChannel(
id: 'ben',
name: 'Default',
description: 'Grant this app the ability to show notifications',
importance: AndroidNotificationChannelImportance.HIGH);
//...
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
static Future<void> _firebaseMessagingBackgroundHandler(
RemoteMessage message) async {
await LocalNotifications.createNotification(
title: "Basic",
content: "Notification",
id: 0,
actions: [
NotificationAction(
actionText: 'accept',
callback: callBack,
payload: 'accept',
launchesApp: true,
),
NotificationAction(
actionText: 'reject',
callback: callBack,
payload: 'reject',
launchesApp: false,
),
],
androidSettings: new AndroidSettings(channel: channel));
static callBack(String payload) {
FlutterRingtonePlayer.stop();
}
}
I can't see the local notification when app is terminated or is in background!
[!] Unable to determine Swift version for the following pods:
- `local_notifications` does not specify a Swift version and none of the targets (`Runner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
it is displaying images as icons in notifications, how can we send image as big picture style
Does it support custom layouts such as placing play/pause buttons on the notification for a music player ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.