Hi guys,
I would like to find a way to send general and individual push notifications to IOS, android and web devices. Through a bit of searching I came across with OneSignal.
The problem is, it works on IOS/Android, but not on web. So you have to use some javascript.
Do you know a better solution?
I’ve tried it so far, but I keep getting the same error. Does anyone have an idea how to proceed?
My code:
void main() {
WidgetsFlutterBinding.ensureInitialized();
Future.delayed(Duration(seconds: 1), () {});
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: OneSignalTestScreen());
}}
class OneSignalTestScreen extends StatefulWidget {
const OneSignalTestScreen({super.key});
@override
State createState() => _OneSignalTestScreenState();
}
class _OneSignalTestScreenState extends State {
get http => null;@override
void initState() {
super.initState();
initializeScreen();}var uuid = Uuid().v4();
final String _oneSignalId = “xxxxxxxxxxxxxxxxxxxxxxxxxxx”;
OneSignalHelper oneSignalHelper = OneSignalHelper();Future initializeScreen() async {
if (!kIsWeb) {
await oneSignalHelper.initNative(
oneSignalId: _oneSignalId,
oneSignalUserId: uuid,
addClickListenerCallback: () {});
} else {}}@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(),
body: Container(),
);}
}
index.html:
test_notify
The error I get is this one:
WorkerMessenger.js:118
`[Worker Messenger] [Page → SW] Could not get ServiceWorkerRegistration to postMessage!
I have seen that several people have this error, but no solution has helped me…
Thank you for your help