I need help, there's an error when calling Local Notification.
For the initState :
initState() {
super.initState();
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid =
new AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
FlutterLocalNotificationsPlugin().initialize(initializationSettings, onSelectNotification: onSelectNotification);
}
For the function :
showNotification() async {
var android = new AndroidNotificationDetails('Channel ID', 'Channel Name', 'channelDescription');
var iOS = new IOSNotificationDetails();
var platform = new NotificationDetails(android, iOS);
await flutterLocalNotificationsPlugin.show(
0, 'New Notification', 'Flutter Local Notif', platform,payload: 'test notification');
}
The error is "PlatformException (PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null))"
I've already tried on the documentation and also youtube, but I always get this error message
Displaying a notification in Flutter To display a notification, we need to create a platform-specific NotificationDetails instance, which takes in arguments that are unique to each platform. AndroidNotificationDetails handles the configuration of notifications in Android devices.
To achieve an image on local notification, first add the awesome_notifications Flutter package by adding the following lines in pubspec. yaml file. awesome_notifications is the best flutter package we got to show local notifications in the Flutter app.
In the main app target, select Signing & Capabilities > All > + Capability and then search "push." Double-click on Push Notifications to enable it. Next, enable Background Modes and check Remote Notifications. Now you are ready to send notifications from the OneSignal dashboard!
I have faced this, and in my case it was an icon problem app_icon
in your initState
function replace this
var initializationSettingsAndroid = new AndroidInitializationSettings('app_icon');
with this
var initializationSettingsAndroid = new AndroidInitializationSettings('@mipmap/ic_launcher');
Hope this helps you.
Add your app_icon.png
to MY_PROJECT\android\app\src\main\res\drawable\app_icon.png
However, for me the error was in androidInitialization. I was initializing it this way:
var androidInit = AndroidInitializationSettings('app_icon.png');
Here, the .png
shouldn't be added. I know this might be silly but if it helps anyone out there facing the same problem then there you go! This is the correct method:
var androidInit = AndroidInitializationSettings('app_icon');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With