Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement flutter web local notification?

I'm wondering if I can implement local notification in flutter web? I saw that I can create local notification for mobile app Android or IOS but is it possible to use it for web app? or any other alternative to accomplish it?

like image 302
Ganesh Kumar Avatar asked Aug 16 '26 00:08

Ganesh Kumar


1 Answers

Just use the class Notification in dart:html package. You can do something like this:

import 'dart:html' as web;

Future<void> showNotification( String message ) async {
  var permission = web.Notification.permission;
  if (permission != 'granted') {
    permission = await web.Notification.requestPermission();
  }
  if (permission == 'granted') {
    web.Notification( message );
  }    
}

More info about the javascript notification API here: https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API

like image 148
jglatre Avatar answered Aug 18 '26 11:08

jglatre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!