createclient method
add this for multithread on flutter apps
Implementation
Future<Map> createclient({
required int clientId,
int clientUserId = 0,
TelegramClientLibraryTdlibOptionParameter? clientOption,
bool isBot = false,
bool isVoid = false,
bool isAutoSetOptionIfEmpty = true,
}) async {
final Map client_new_option = client_option.rawData.clone();
if (clientOption != null) {
clientOption.rawData.remove("@type");
client_new_option.addAll(clientOption.rawData);
}
if (isAutoSetOptionIfEmpty) {
final Map<String, String> tdlib_option_should_not_empty_string = {
"system_language_code": "en",
"device_model": "Unknown",
"application_version": "v1",
"api_hash": client_option.api_hash ?? "",
};
tdlib_option_should_not_empty_string.forEach((key, value) {
try {
if (client_new_option[key] is String == false) {
client_new_option[key] = value;
return;
}
final String value_default = client_new_option[key].toString().trim();
if (value_default.isEmpty) {
client_new_option[key] = value;
}
} catch (e) {
client_new_option[key] = value;
}
});
final Map<String, num> tdlib_option_should_not_empty_num = {
"api_id": client_option.api_id ?? 0
};
tdlib_option_should_not_empty_num.forEach((key, value) {
try {
if (client_new_option[key] is num == false) {
client_new_option[key] = value;
return;
}
final num value_default = client_new_option[key];
if (value_default < 1) {
client_new_option[key] = value;
}
} catch (e) {
client_new_option[key] = value;
}
});
}
clients[clientId] = TdlibClient(
client_id: clientId,
client_tg_user_id: clientUserId,
is_bot: isBot,
client_option: client_new_option,
);
return await invoke(
"setTdlibParameters",
parameters: client_new_option,
clientId: clientId,
isVoid: isVoid,
isUseCache: false,
durationCacheExpire: null,
isInvokeThrowOnError: false,
);
}