Today I’ll tell you that how you can setup Local Notification Plugin on Flutter App. Using Plugin in flutter is not difficult but in case of Flutter Local Notification. We need to setup some configuration before start using it.

Flutter Local Notification Youtube Video

Step 1 : Add flutter_local_notifications dependency in your pubspec.yaml file.

Step 2 : Add VIBRATE and RECEIVE_BOOT_COMPLETED permission to your AndroidManifest.xml [ Optional ]

If you don’t give these permission to your app then you can’t use Vibrate and Schedule Feature which is Available in this plugin.

Step 3: Add image inside drawable directory for Notificaiton Icon [ Optional ]
( flutter_app_name > android > app > src > res > drawable > app_icon.png )

If you don’t add image for notification icon then you have to tell the app to use app icon, which is stored in ‘mipmap’. [ ANDROID ]

If you are reading this article then you must had ever seen the notification and with the notification there is a small icon.

This image is for that purpose. This image will be shown with our notification.

Step 4 : Add a Tone(Music) for Notification [ Optional ]

If you don’t add tone for notification then it will the default tone of you notification.

To add custom Tone (Music)

  1. Make a directory inside res directory.
  2. Keep a small Audio (Music) there and remember the file name.

( flutter_app_name > android > app > src > res > raw > slow_spring_board.mp3 )

Step 5 : Now It’s time to come to CODING.

So first we will initialize the Flutter Notification Plugin .It is good to initialize it inside initState(), so that as soon as our app start it get initialize it and we can us8e it anytime.

At the time of initializing we have to keep TWO things in our mind.

1. We have to define the app icon, In the above image you can see this ‘new AndroidInitializationSettings(‘app_icon’)’ . Here app_icon is image name which we had put inside the drawable directory.
If you didn’t put that then you can use default icon for that you have to use ‘@mipmap/ic_launcher’ instead of ‘app_icon’.

2. At the second last line ‘selectNotification: onSelectNotification’. This line is responsible for the action which is going to be happen when we will click on the Notification. This method must return Future and this method must have a string paramter which will be payload.

below you can see onSelectNotification method where I am showing a Dialog. You can open New page and can show the detailed Notification also

Payload : Notification messages can contain an optional data that is known as payload

This is basic setup where I am havig 3 button and In above code you can see that corresponding to each button there is different methods

Button 1 : _showNotificationWithSound
Button 2 :
_showNotificationWithoutSound
Button 3 :
_showNotificationWithDefaultSound

but there is nothing inside all the method. I’ll write that in next step.

Step 6 : Let’s Define All 3 methods

I hope that you got the idea that how you can setup a Local Notification Plugin in Flutter.

If you find any difficulties while reading or you have any doubts.
Let me know may be I can help you with that
If you like it then don’t be strange clap before leaving.

Flutter Local Notification has lots of features and it’s little difficult to set up. As I had shown you the basic setup, Now you can go through the official Github Repo and implement other features also. Now you will not face any problem as I had discussed the Setup.

If you face any problem in implementing other features let me know I’ll help you that or I’ll write one more story.

Web🌐/ Mobile📱/ GraphQL / Cloud☁️ . Full-time programmer, part-time content creator, and Freelancer.