startNotifications method
Future<void>
startNotifications(
- StartNotificationsParams options,
- void callback(
- ReadResult result
override
Implementation
@override
Future<void> startNotifications(StartNotificationsParams options,
void Function(ReadResult result) callback) async {
var optionsMap = options.getMap();
optionsMap['callbackName'] = 'startNotifications';
bool cancelStream = false;
var brodcastStream =
_eventChannel.receiveBroadcastStream(optionsMap).listen((event) {
if (event == null || event["status"] == "success") {
return;
}
if (event["status"] == "error") {
cancelStream = true;
return;
}
callback(event['value']);
cancelStream = true;
});
Timer.periodic(const Duration(milliseconds: 500), (timer) {
if (cancelStream) {
brodcastStream.cancel();
timer.cancel();
}
});
}