init static method
dynamic
init({
- required UIKitSettings uiKitSettings,
- dynamic onSuccess(
- String successMessage
- dynamic onError()?,
method initializes the settings required for CometChat
We suggest you call the init() method on app startup
its necessary to first populate uiKitSettings inorder to call init.
Implementation
static init(
{required UIKitSettings uiKitSettings,
Function(String successMessage)? onSuccess,
Function(CometChatException e)? onError}) async {
//if (!checkAuthSettings(onError)) return;
authenticationSettings = uiKitSettings;
AppSettings appSettings = (AppSettingsBuilder()
..subscriptionType = authenticationSettings?.subscriptionType ??
CometChatSubscriptionType.allUsers
..region = authenticationSettings?.region
..autoEstablishSocketConnection =
authenticationSettings?.autoEstablishSocketConnection ?? true
..adminHost = authenticationSettings?.adminHost
..clientHost = authenticationSettings?.clientHost)
.build();
await CometChat.init(authenticationSettings!.appId!, appSettings,
onSuccess: (String successMessage) async {
User? loggedInUser = await getLoggedInUser();
if (loggedInUser != null) {
CometChatUIKit.loggedInUser = loggedInUser;
_initiateAfterLogin();
}
//executing custom onSuccess handler when CometChat SDK is initialized successfully
getConversationUpdateSettings();
if (onSuccess != null) {
try {
onSuccess(successMessage);
} catch (e) {
if (kDebugMode) {
debugPrint(
"CometChat SDK is initialized successfully but failed to execute onSuccess callback");
}
}
}
CometChat.setSource("uikit-v4", Platform.operatingSystem, "flutter");
}, onError: (CometChatException exception) {
//executing custom onError handler when CometChat SDK could not be initialized
if (onError != null) {
try {
onError(exception);
} catch (e) {
if (kDebugMode) {
debugPrint(
"CometChat SDK could not be initialized and failed to execute onError callback");
}
}
}
});
}