7

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

amit.flutter
  • 883
  • 9
  • 27
Ayush Singh
  • 1,409
  • 3
  • 19
  • 31

1 Answers1

3

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.

rmtmckenzie
  • 37,718
  • 9
  • 112
  • 99