HatangChat class

Entry point of the SDK. Call configure once at startup, then open a chat, identify the user and listen to events.

Constructors

HatangChat.forEngine(ChatEngine engine, {String siteId = 'site_test', HatangChatThemeMode themeMode = HatangChatThemeMode.site, GlobalKey<NavigatorState>? navigatorKey, HatangCommerce commerce = HatangCommerce.standard, HatangFilePick? pickFile})
Builds an instance around an existing engine (host tests).
factory

Properties

availability → Stream<Availability>
Team availability.
no setter
bottomPadding → double
Current bottom padding.
no setter
bottomPaddingListenable → ValueListenable<double>
bottomPadding as a listenable, for widgets that follow it.
no setter
commerce → HatangCommerce
How purchases from chat cards are handled (in-app purchase hooks, external checkout on or off). See HatangCommerce.
final
connectionState → Stream<HatangConnectionState>
Socket state.
no setter
currentAvailability → Availability
Current availability.
no setter
currentConnectionState → HatangConnectionState
Current connection state.
no setter
darkTheme → HatangChatTheme?
Dark theme from configure.
final
engine → ChatEngine
The state machine (advanced hosts; the API above covers the rest).
final
events → Stream<HatangEvent>
Host-facing events (ready, opened, closed, messages, status, conversions, session changes, protocol outdated).
no setter
hashCode → int
The hash code for this object.
no setterinherited
isOpen → bool
A chat screen is on screen.
no setter
Navigator used to open the chat without a context.
final
pickFile → HatangFilePick?
Picks a file for the composer's "File" option; null offers photos only. package:hatang_chat/file_picker.dart has one (hatangFilePicker there), or pass your own. See HatangFilePick.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
session → HatangSession
The current session.
no setter
siteId → String
The site.
final
strings → Map<HatangLocale, HatangChatStrings>?
String overrides from configure.
final
theme → HatangChatTheme?
Light theme from configure.
final
themeMode → HatangChatThemeMode
Theme mode from configure.
final
unreadCount → Stream<int>
Unread count while the chat is closed.
no setter
unreadCountListenable → ValueListenable<int>
Unread count as a listenable (for badges).
no setter

Methods

clearPushToken() → Future<void>
Unregisters the push token.
connect() → Future<void>
Bootstraps and connects (when configure ran with autoConnect: false or after disconnect).
disconnect() → Future<void>
Closes the socket; the SDK stays configured.
dispose() → void
Releases everything; configure again to use the SDK afterwards.
handleNotification(Map<Object?, Object?> data, {BuildContext? context}) → Future<bool>
Opens the conversation a Hatang notification points at. Returns false for foreign payloads. Without context the navigatorKey is used; when the SDK is not ready yet (cold start) the intent is parked until it is.
identify(HatangUser user) → Future<void>
Attaches the host user's identity. Pass a hash (HMAC-SHA256 of the user id with the site's identity secret, computed on your server) for verified identities.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
purchaseToken(String userId) → String
The app account token for one of your users: pass it as applicationUserName (iOS, StoreKit's appAccountToken) or obfuscatedAccountId (Google Play) when buying, so the stores' notifications reach this customer in Hatang.
pushEvent(String name, [Map<String, Object?>? data]) → Future<void>
Records a custom event on the active conversation.
reportPurchase({required String platform, required String storeProductId, String? transactionId, num? amount, String? currency, String? signedTransaction, String? purchaseToken, String? productType, String? kind}) → Future<bool>
After a successful in-app purchase. platform is ios or android. Pass the store's proof so Hatang verifies it and records it for this person: signedTransaction (iOS, the StoreKit 2 JWS — in_app_purchase gives it as verificationData.serverVerificationData) or purchaseToken with productType subs / inapp (Android; Hatang acknowledges it). kind is consumable or non_consumable for Android one-time products.
reset() → Future<void>
Forgets this visitor (sign-out): fresh visitor, old token revoked.
restoreSession(String linkToken) → Future<void>
Restores the session behind a "we replied" magic link token.
setBottomPadding(double px) → void
Extra space under the composer and the launcher when the chat sits above a host tab bar or bottom sheet. Screens and launchers already shown move.
setData(Map<String, Object?> data) → Future<void>
Attaches custom attributes shown to agents.
setLocale(HatangLocale locale) → Future<void>
Switches the language.
setPushToken(String token, {required PushProvider provider}) → Future<void>
Registers the device push token (FCM or APNs) for this visitor. Safe to call before the SDK is ready; the registration is deferred and repeated when the visitor or app version changes.
setScreen(String name, {Map<String, String>? params}) → void
Reports the screen the app shows (the Live board and page views).
showMessage(String text, {String? senderName}) → void
Shows a local-only assistant bubble (never sent to the gateway).
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

configuredPickFile → HatangFilePick?
The file picker given to configure, for controllers that build their own attachment picker; null when not configured or none was given.
no setter
instance → HatangChat
The configured instance; throws when configure has not run.
no setter
isConfigured → bool
configure has run.
no setter

Static Methods

close() → void
Pops the chat screen opened by open / handleNotification.
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, Client? httpClient, SocketConnector? connector, KeyValueStore? secureStore, KeyValueStore? prefsStore}) → Future<void>
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.
debugSetInstance(HatangChat? instance) → void
Replaces the instance (host tests).
isHatangNotification(Map<Object?, Object?> data) → bool
true when a notification payload came from Hatang (hatang: "1", also accepted nested under data).
linkTokenFromUri(Uri uri) → String?
The restore token inside a magic link: /c/<token> paths or a hatang_restore query parameter. null when uri is not one.
open(BuildContext context, {String? conversationId, bool fullscreenDialog = true}) → Future<void>
Pushes the chat screen as a full-screen dialog route.
openInbox(BuildContext context) → Future<void>
Pushes the visitor's conversation list (HatangChatInbox).