Closed GirishVerm closed 2 years ago
Hi @GirishVerm, We'd be glad to assist.
It is currently not possible to call Pushy.setNotificationListener()
outside of the lib/main.dart
file. It appears you are trying to call this method from within your home page widget. This is unsupported.
Please find a sample supported implementation in the Flutter Demo app's lib/main.dart.
iOS device unable to listen for notifications when setNotificationListener is used.
I am not using firebase-messaging or any other push notification service, what's odd is my code was working yesterday but isn't working today with a similar setup.
I have set up my main file according to the documentation but its not working. So I set a notification listener in my home page that responds with error "Pushy: Error retrieving handle for Flutter callbacks".
SETUP in MAIN FILE ` void backgroundNotificationListener(Map<String, dynamic> data) { // Print notification payload data print('Received notification: $data');
// Notification title String notificationTitle = 'MyApp';
// Attempt to extract the "message" property from the payload: {"message":"Hello World!"} String notificationText = data['message'] ?? 'Hello World!';
// Android: Displays a system notification // iOS: Displays an alert dialog Pushy.notify(notificationTitle, notificationText, data);
// Clear iOS app badge number Pushy.clearBadge(); }
void main() async {
WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); Pushy.toggleInAppBanner(true);
//this listener doesn't respond at all, no errors and no notifications. Pushy.setNotificationListener(backgroundNotificationListener);
//initLogic takes me to home page runApp(initLogic());
}`
SETUP in HOME PAGE
` @override void initState() { print("listening"); Pushy.listen();
//here the setNotificationListener prints "Pushy: Error retrieving handle for Flutter callbacks" Pushy.setNotificationListener((data) { print('Received notification: $data');
//...other stuff in initState
}`