startEnabledNotifications method

  1. @override
Future<void> startEnabledNotifications(
  1. void callback(
    1. bool result
    )
)
override

Implementation

@override
Future<void> startEnabledNotifications(
    void Function(bool result) callback) async {
  var cancelStream = false;
  var brodcastStream = _eventChannel.receiveBroadcastStream(
      {'callbackName': 'onEnabledChanged'}).listen((event) {
    if (event["status"] != "error") {
      callback(event['value']);
    }
    cancelStream = true;
  });

  Timer.periodic(const Duration(milliseconds: 500), (timer) {
    if (cancelStream) {
      brodcastStream.cancel();
      timer.cancel();
    }
  });
}