configure static method
- required String siteId,
- required String appKey,
- Uri? baseUrl,
- HatangLocale? locale,
- HatangChatThemeMode themeMode = HatangChatThemeMode.site,
- HatangChatTheme? theme,
- HatangChatTheme? darkTheme,
- Map<
HatangLocale, HatangChatStrings> ? strings, - HatangLogger? logger,
- HatangAppInfo? appInfo,
- bool autoConnect = true,
- bool openOnProactiveMessage = true,
- HatangCommerce commerce = HatangCommerce.standard,
- HatangFilePick? pickFile,
- @visibleForTesting Client? httpClient,
- @visibleForTesting SocketConnector? connector,
- @visibleForTesting KeyValueStore? secureStore,
- @visibleForTesting KeyValueStore? prefsStore,
Configures the SDK for siteId with the site app key appKey
(hak_…, from the website's Mobile apps tab in the dashboard). Calling it again
replaces the previous instance.
baseUrl defaults to the production gateway. locale forces a language
(otherwise: the stored choice, the site default, the device). themeMode,
theme and darkTheme control colours; strings overrides wording per
locale. Pass a navigatorKey so handleNotification and proactive
conversations can open the chat without a context. With autoConnect
(default) the SDK bootstraps and connects at once.
Implementation
static Future<void> configure({
required String siteId,
required String appKey,
Uri? baseUrl,
HatangLocale? locale,
HatangChatThemeMode themeMode = HatangChatThemeMode.site,
HatangChatTheme? theme,
HatangChatTheme? darkTheme,
Map<HatangLocale, HatangChatStrings>? strings,
GlobalKey<NavigatorState>? navigatorKey,
HatangLogger? logger,
HatangAppInfo? appInfo,
bool autoConnect = true,
bool openOnProactiveMessage = true,
HatangCommerce commerce = HatangCommerce.standard,
HatangFilePick? pickFile,
@visibleForTesting http.Client? httpClient,
@visibleForTesting SocketConnector? connector,
@visibleForTesting KeyValueStore? secureStore,
@visibleForTesting KeyValueStore? prefsStore,
}) async {
if (siteId.isEmpty) throw ArgumentError.value(siteId, 'siteId', 'must not be empty');
if (appKey.isEmpty) throw ArgumentError.value(appKey, 'appKey', 'must not be empty');
_instance?.dispose();
final info = appInfo ?? await loadAppInfo();
final prefs = prefsStore ?? PrefsStore();
final secure = secureStore ?? SecureStore(fallback: prefs);
final engine = ChatEngine(
api: WidgetApi(
baseUrl: baseUrl ?? hatangDefaultBaseUrl,
siteId: siteId,
appKey: appKey,
userAgent: info.userAgent,
client: httpClient,
),
connector: connector ?? connectWebSocket,
store: SessionStore(siteId: siteId, secure: secure, prefs: prefs),
appInfo: info,
logger: logger,
preferredLocale: locale?.code,
openOnProactiveMessage: openOnProactiveMessage,
);
final sdk = HatangChat._(
engine: engine,
siteId: siteId,
themeMode: themeMode,
theme: theme,
darkTheme: darkTheme,
strings: strings,
navigatorKey: navigatorKey,
commerce: commerce,
pickFile: pickFile,
lifecycle: HatangLifecycleObserver(engine),
);
_instance = sdk;
sdk._lifecycle?.attach();
if (autoConnect) await engine.start();
}