checkAndRequestNotificationPermission method

Future<bool> checkAndRequestNotificationPermission()
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Notification Click Listener

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Implementation

// Stream<int> notificationClickedListener() {
//   final controller = StreamController<int>();
//   _channel.setMethodCallHandler((call) async {
//     if (call.method == 'notificationClick') {
//       final id = call.arguments ?? -1;
//       controller.add(id);
//     }
//   });
//   return controller.stream;
// }

///```xml
///<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
///```
Future<bool> checkAndRequestNotificationPermission() async {
  final completer = Completer<bool>();
  _channel.setMethodCallHandler((call) async {
    if (call.method == 'notiPermissionResult') {
      final isGranted = call.arguments['isGranted'] ?? false;
      completer.complete(isGranted);
    } else {
      completer.complete(false);
    }
  });
  // send android
  _channel.invokeMethod<bool>('$_name/askNotificationPermission').then((
    isGranted,
  ) {
    if (isGranted == null) return;
    completer.complete(isGranted);
  });

  return completer.future;
}