init method

  1. @override
Future<bool> init(
  1. dynamic backgroundMessageHandler(
    1. Map
    )?, [
  2. String? notificationChannel = "messages",
  3. bool loggerEnabled = false,
  4. bool askPermissions = true,
  5. bool serverLoggerEnabled = false,
  6. String? applicationId,
  7. bool enablePushOnForeground = true,
  8. String? environment,
])
override

Implementation

@override
Future<bool> init(Function(Map<dynamic, dynamic>)? backgroundMessageHandler,
    [String? notificationChannel = "messages",
    bool loggerEnabled = false,
    bool askPermissions = true,
    bool serverLoggerEnabled = false,
    String? applicationId,
    bool enablePushOnForeground = true,
    String? environment]) async {
  methodChannel.setMethodCallHandler(_handle);
  print(
      "[PushedPlugin][Android][Dart] init loggerEnabled=$loggerEnabled askPermissions=$askPermissions applicationId=$applicationId environment=$environment");
  var rawHandle = 0;
  if (backgroundMessageHandler != null) {
    rawHandle = PluginUtilities.getCallbackHandle(backgroundMessageHandler)
            ?.toRawHandle() ??
        0;
  }
  final result = await methodChannel.invokeMethod("init", {
    "backgroundHandle": rawHandle,
    "channel": notificationChannel,
    "logger": loggerEnabled,
    "askpermissions": askPermissions,
    "serverLoggerEnabled": serverLoggerEnabled,
    "enablePushOnForeground": enablePushOnForeground,
    if (applicationId != null && applicationId.isNotEmpty)
      "applicationId": applicationId,
    if (environment != null && environment.isNotEmpty) "environment": environment,
  });
  if (result) {
    FlutterPushedMessagingPlatform.status =
        ServiceStatus.values[await methodChannel.invokeMethod("getStatus")];
    FlutterPushedMessagingPlatform.pushToken =
        await methodChannel.invokeMethod("getToken");
    print(
        "[PushedPlugin][Android][Dart] init success status=${FlutterPushedMessagingPlatform.status} token=${FlutterPushedMessagingPlatform.pushToken}");
  }
  return result;
}