'Dart Flutter The method 'init' isn't defined for the type 'OneSignal'

I'm trying to make a system of sending notifications to the phone with OneSignal.

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:kelimeogrenmeuygulamasi/arayuzEkrani.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Firebase.initializeApp();
  OneSignal.shared.init("YOUR ONESIGNAL APP ID", iOSSettings: {
    OSiOSSettings.autoPrompt: false,
    OSiOSSettings.inAppLaunchUrl: false
  });
  runApp(mainApp());
}

In this code, I get an error in the init part.

Error:

enter image description here

How can I resolve this error?



Solution 1:[1]

i am facing same error, i was searching and found out that setAppId instead of init maybe works, so try it

Solution 2:[2]

use below code

void configOneSignel()
{
  OneSignal.shared.setAppId('xxxxxxxxxxxxxxx-app-id-xxxxxxxxxxxxxxxxxx');
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nidhi Makdani
Solution 2 Vismay Viradiya