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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With