In this story, we’re gonna see how to manage Do Not Disturb settings in android using a flutter plugin called flutter_dnd.
As we know flutter doesn’t provide any direct interface to communicate with system settings and the only solution we have is to write our own native bridges to communicate and if you’re coming from non-native mobile application development background it won’t be a painless job to do.
So I’ve made a simple plugin called flutter_dnd which will get the job done!
- Add package dependency.
Add flutter_dnd package dependency in your pubspec.yaml
2. Add notification access policy permission in your manifest.
3. Checking notification policy access.
4. Allow DND access to the application.
On calling FlutterDnd.gotoPolicySettings() will take you to system settings to get permission. the user has to choose the application and allow access to it.
5. Say hello to DND filters!
Before we try to turn on the DND mode, let’s understand some of the DND filters in the first place so we can decide which one is relevant to use.
INTERRUPTION_FILTER_ALL — DND is turned off.
INTERRUPTION_FILTER_PRIORITY — Only prioritized notifications will be shown.
INTERRUPTION_FILTER_NONE — Turn on DND, Show nothing in the notification tray.
INTERRUPTION_FILTER_ALARMS — Show alarm only.
6. Let’s apply some filters
Now you’re authorized to make changes in DND settings, call the FlutterDnd.setInterruptionFilter()
method with an appropriate filter.
Also, find a more detailed example available at my Github repository.
Thank you!