hey guys when I use onDidReceiveBackgroundNotificationResponse in flutter_local_notification I got an error can someone help me?
actually I want navigate to second page after user select my notification in background mode but I got this problem
hey guys when I use onDidReceiveBackgroundNotificationResponse in flutter_local_notification I got an error can someone help me?
actually I want navigate to second page after user select my notification in background mode but I got this problem
On
actually I want navigate to second page after user select my notification in background mode but I got this problem
Answering on how to navigate from a Top Level Function:
I made a Singleton which is accesible from Top Level Function. This singleton manages a Stream and emits a new event everytime the user taps on a notification.
import 'dart:async';
import 'package:listsapp/common/types/types.dart';
class ActionNotificationService {
factory ActionNotificationService() => _instance ??= ActionNotificationService._();
ActionNotificationService._() : _notificationsController = StreamController.broadcast();
static ActionNotificationService? _instance;
final StreamController<JSON> _notificationsController;
void add(JSON payload) => _notificationsController.add(payload);
Stream<JSON> getNotificationOpenedStream() => _notificationsController.stream;
void close() {
_notificationsController.close();
}
}
Inside my app I listen to this stream and navigate to the specific screen.
Also, remember to close the singleton stream when your application doesn't need it no more.
Put the definition of function used as backgroundHandler outside of any class.
For example:
For more clarity, could you post the whole page code?