While your app can be fine without advanced ways to build your users’ loyalty, notifications are a really important feature that you should consider implementing. It can be a reminder on how much you love your users or a way to remind them of important events. Well, in Flutter using this great tool is pretty easy but you need to know a few concepts to master it! In this tutorial we’ll see how to create a simple notification and a scheduled one.
This is the plugin we’ll use and it’s the most popular one on pub.dev. You can find it here and add it easily to your project:
With this we can schedule timed notifications without caring for the timezones of the device.
A simple notification
Let’s do an easy “hello world”! First we need to initialize the plugin with iOS and Android specifications. For Android we’ll need to specify the channel and the icon. The channel can be initialized directly but the icon need to be added to the initialization.
iOS initialization is pretty straightforward too:
Also we want to init “Timezones” plugin. The final code for initialization will result:
After that we are ready to trigger a notification!
Then we can finally create our notification:
Scheduling a notification requires the same things as above but also a date time. It’s best here to use directly Timezone plugin as it will take care of pretty much everything. We are now scheduling a notification to 5 seconds in the future:
Local notifications ca be a bit hard to initialize but they are a breeze to use once we understand them. This plugin offers a lot of options to customize notifications like media embedding and selection behavior but I’ll leave them to you to discover!
For more awesome Flutter tutorials check out our website!