Start a Project

Custom Notification Dialog with Sound in Flutter

In this blog, we will explore the Custom Notification Dialog functionality in Flutter. In the mobile apps, we use Dialog everywhere from alerting some situations to the user to getting some feedback from the user. Before starting to create a custom dialog, we know about what is the custom dialog in Flutter.

Flutter Custom Alert Dialog

Not every situation will benefit from Simple Alert Dialogue. You can utilize the Dialogue widget to create more complex custom dialogues. Here, we return the Dialogue widget in place of the AlertDialog.

Read More About Flutter App Development From Mobikul.

In the above example, we are creating a simple custom dialog with two buttons. so we have created a custom dialog now we need to add this dialog on Notification, before adding this first we need to know about the notification in a flutter.

Notification

A notification is a message that Android displays outside your app’s UI to provide the user with reminders, communication from other people, or other timely information from your app.

you can check our other blogs on Flutter notification.

Flutter Code

Now we are creating a notification channel in Flutter with a custom notification sound.

  1. First, you need to create a raw resource file in your Android native res folder. The raw folder holds media files such as video and audio. Android currently supports 3gp, mp4, m4a, aac,wav, and ts audio file formats. 

2. In the flutter we need to create two specific platform notification channels so now we are creating the two different platform-specific channels.

In the above code, we are creating the “androidPlatformChannelSpecifics” channel with custom sound. you can see we have passed our sound file name in “RawResourceAndroidNotificationSound”.

Note:-You don’t need to pass a sound file extension, only pass the file name.

3. Now we are creating an iOS notification channel in the below code.

Complete code

Output

Conclusion

We have learned about the Custom Notification Dialog with Custom Sound in Flutter.

  1. First, we have created a custom dialog in Flutter.
  2. We have created a specific platform notification channel.

Thanks for reading this blog. You can also check other blogs from here for more knowledge.

Exit mobile version