Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To make interactive notification in Flutter [closed]

Tags:

flutter

I am making a music player app in Flutter and I am not able to find any way to make a widget or something that is displayed in the notification tray and can play or pause the music. Is it even possible to achieve this in flutter and if yes, how can I do that? Thanks in advance.enter image description here

like image 379
Ayush Singh Avatar asked Aug 27 '18 18:08

Ayush Singh


People also ask

How do I turn off notifications on Flutter?

Canceling a local notification in Flutter To cancel a specific notification, let's create a new method called cancelNotification , which will contain the cancel method from the FlutterLocalNotificationsPlugin object. This method expects an argument, which is the id of the notification.

How do you handle background notifications in Flutter?

Handling Interaction Since notifications are a visible cue, it is common for users to interact with them (by pressing). The default behavior on both Android and iOS is to open the application. If the application is terminated it will be started; if it is in the background it will be brought to the foreground.

How do I handle the Firebase notification when an app is in foreground?

Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you'll need to write code to handle the onMessageReceived callback.


2 Answers

Because of the way android notifications work, you can only really customize them with android code (for now at least). So unfortunately, you're going to have to write some native code here.

The actual notification part is the exact same as directly with android in this case, so you can simply look that up. Here's a start though.

The other part to this is that you need to communicate between your flutter code and the native code which handles the notification. To do so, you need to use Platform Channels. Platform channels are things you register so that you can send data back and forth between java/kotlin/objc/swift and dart, in the form of events or 'method calls'. The docs do a better job than me of explaining how to use them.

like image 115
rmtmckenzie Avatar answered Oct 21 '22 04:10

rmtmckenzie


This new package has something like it.. I have not tried it though and it's still pretty new https://pub.dev/packages/audio_manager

like image 3
lordvidex Avatar answered Oct 21 '22 02:10

lordvidex