init static method

Future<void> init(
  1. String appId,
  2. AppSettings appSettings, {
  3. required dynamic onSuccess(
    1. String successMessage
    )?,
  4. required dynamic onError(
    1. CometChatException e
    )?,
})

method initializes the settings required for CometChat

We suggest you call the init() method on app startup

appId refers to your CometChat App ID. region The region where the app was created.

Implementation

static Future<void> init(String appId, AppSettings appSettings,
    {required Function(String successMessage)? onSuccess,
    required Function(CometChatException e)? onError}) async {
  try {
    final arguments = {
      'appId': appId,
      'roles': appSettings.roles,
      'region': appSettings.region,
      'adminHost': appSettings.adminHost,
      'clientHost': appSettings.clientHost,
      'subscriptionType': appSettings.subscriptionType,
      'autoEstablishSocketConnection':
          appSettings.autoEstablishSocketConnection,
      'sdkVersion': null,
      'platform': null
    };
    final result = await channel.invokeMethod('init', arguments);
    initializetestmessageStream();
    nativeStream?.listen((event) {});
    if (onSuccess != null) onSuccess(result);
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}