I want to show notification daily on a specified time and I have implemented the code to show daily notification but it is not working not showing a notification at the time I want to call. I am using this plugin link
When I run The App I got this warning on Console here is the screenshot
Is my implementation of the code wrong? Here is the code
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'dart:async';
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
showNotification() async{
var time = new Time(3,51, 0);//at 3.30
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails('repeatDailyAtTime channel id',
'repeatDailyAtTime channel name', 'repeatDailyAtTime description');
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(
0,
'Teer Result Time',
'Open The App and check for the Result',
time,
platformChannelSpecifics);
}
@override
void initState() {
// TODO: implement initState
super.initState();
showNotification();
}
@override
Widget build(BuildContext context) {
return Container(
);
}
}
I just had the same problem, I found that I didn't add some required permissions and receivers in my manifest, all the details are written in the docs under the Scheduled notifications title, as well as this link to the example project manifest as a reference.
Hope it helps someone.
You have to first initialize Local Notification plugin.
Just add the initialization code to your initstate, as shown below:
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'dart:async';
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
showNotification() async{
var time = new Time(3,51, 0);//at 3.30
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails('repeatDailyAtTime channel id',
'repeatDailyAtTime channel name', 'repeatDailyAtTime description');
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(
0,
'Teer Result Time',
'Open The App and check for the Result',
time,
platformChannelSpecifics);
}
@override
void initState() {
// TODO: implement initState
super.initState();
//-------------------- Initialization Code---------------------
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
//--------------------------------------
showNotification();
}
@override
Widget build(BuildContext context) {
return Container(
);
}
}
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