init
Introduction
Init the SDK and TUIKit.
The following steps are needed for initialize the TUIKit:
Specify the SDKAppID.
Specify LogLevelEnum.
Specify V2TimSDKListener.
Specify TIMCallback, for details, see this document.
Specify TIMUIKitConfig.
Specify the language
, do not specified means using the language with system.
Initialize the TUIKit by invoking initSDK
.
Parameter details
Parameter name | Parameter type | Required | Platform | Description |
---|---|---|---|---|
onTUIKitCallbackListener | Function(TIMCallback TIMCallback) | no | All | This listener is used to get information including: errors form SDK API / errors form Flutter / some remind information that may need to pop up to prompt users. Usage and details, see this document. |
sdkAppID | int | yes | All | The ID of the application, SDKAppID. |
loglevel | LogLevelEnum | yes | All | Log print level. |
listener | V2TimSDKListener | yes | All | The listener for SDK. |
language | LanguageEnum | no | All | The language on TUIKit, do not specified means using the language with system. |
config | TIMUIKitConfig | no | All | The global configuration of TUIKit. |
Returned template
Future<bool?>
Return value details
name | type | description |
---|---|---|
bool | bool | The result of initialization. |
Code example
final CoreServicesImpl _coreInstance = TIMUIKitCore.getInstance();
V2TimSDKListener sdkListener = V2TimSDKListener(
onConnectFailed: (int code, String error) {
},
onConnectSuccess: () {
},
onConnecting: () {
},
onKickedOffline: () {
},
onSelfInfoUpdated: (V2TimUserFullInfo info) {
},
onUserSigExpired: () {
},
onUserStatusChanged: (List<V2TimUserStatus> userStatusList) {
},
);
final isInitSuccess = await _coreInstance.init(
onTUIKitCallbackListener: (TIMCallback callbackValue) {
switch (callbackValue.type) {
case TIMCallbackType.INFO:
Utils.toast(callbackValue.infoRecommendText!);
break;
case TIMCallbackType.API_ERROR:
print(
"Error from TUIKit: ${callbackValue.errorMsg}, Code: ${callbackValue.errorCode}");
if (callbackValue.errorCode == 10004 &&
callbackValue.errorMsg!.contains("not support @all")) {
Utils.toast("The current group does not support @all");
} else if (callbackValue.errorCode == 80001 &&
callbackValue.errorMsg!.contains("not support @all")) {
Utils.toast("Illegal statement in message");
} else {
Utils.toast(
callbackValue.errorMsg ?? callbackValue.errorCode.toString());
}
break;
case TIMCallbackType.FLUTTER_ERROR:
default:
if (callbackValue.catchError != null) {
Utils.toast(callbackValue.catchError.toString());
} else {
print(callbackValue.stackTrace);
}
}
},
sdkAppID: 0,
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG,
listener: sdkListener,
language: LanguageEnum.en
config: TIMUIKitConfig(isShowOnlineStatus: true)
);
if (isInitSuccess == null || !isInitSuccess) {
Utils.toast("Chat SDK initialization failed");
return;
} else {
Utils.toast("Chat SDK initialized successfully");
}