I'm trying to implement local notifications but I'm facing the NoSuchMethodError, I have debugged the code and find the issue but didn't find the correct solution for it. I have created the notification manager class I'm calling it like this in AddNotification.dart Stateful class
final NotificationManager manager;
const AddNotification(this.manager);
then call it like this in its State class:
widget.manager.showNotificationDaily(1, "Asar", "isNotification", hour, minute);
and in the previous class from where AddNotification is called is I have sent a Notification manager object like this.
class AllSurah extends StatefulWidget {
NotificationManager manager;
@override
_AllSurahState createState() => _AllSurahState();
}
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddNotification(widget.manager)),
);
I have debugged the code and find that the manager is passing null from the previous class from where the NotificationManger object is passed. How can I solve this issue?
CodePudding user response:
Just try the below code:
NotificationManager manager = new NotificationManager();
CodePudding user response:
The problem isn't that you're not passing the variable to the object. Rather the problem is that the manager
variable is null at the moment you're calling showNotificationDaily
on it, which throws the Exception you're seeing.
You can avoid Null Exceptions by using the Null Aware Operator ( ? ), like this:
widget.manager?.showNotificationDaily(1, "Asar", "isNotification", hour, minute);
But that will only avoid an Exception
being thrown. You should really investigate why this variable is being passed as null