hatang_chat library

Hatang live chat for Flutter apps.

await HatangChat.configure(siteId: 'site_…', appKey: 'hak_…');
await HatangChat.open(context);

Classes

AgentAvatar
A team member shown in the chat header.
AgentSummary
The human handling a conversation.
AppContext
Install and build details sent on bootstrap and auth.
Attachment
A file attached to a message.
Availability
Whether the team can answer right now.
BoldToken
Bold text.
BootstrapResponse
What POST /bootstrap returns.
BrToken
A line break.
ChatEngine
The chat state machine: bootstrap → connect → ready → frames, plus every host-facing action. Pure Dart; the Flutter layer wires storage, the socket, lifecycle and widgets around it.
ChatRow
One row of the message list, in display order (oldest first). The list renders them reversed.
ChatState
Immutable snapshot of everything the UI renders.
ClientInfo
The SDK identifying itself on the socket.
CloseCodes
Socket close codes the gateway uses.
ClosedBar
Shown instead of the composer on a closed conversation.
CodeToken
Inline code.
ConversationEventDto
Something that happened in a conversation (status change, handoff, ...).
ConversationPage
A page of the visitor's conversations.
ConversationSummary
A conversation as the gateway reports it on ready / conversation.start.
CsatCard
A rating prompt after resolve.
DayRow
"Today" / "Yesterday" / date.
DeviceRegistration
A device registered for pushes.
FormatToken
One piece of a formatted message (port of format.ts). Never HTML.
GreetingRow
The site greeting, shown while the conversation is empty.
HatangAppInfo
What the SDK tells the gateway about the host app and device. The Flutter layer fills it from package_info_plus and device_info_plus; pass your own to HatangChat.configure to override.
HatangAttachmentPicker
Picks files for the chat and prepares them for upload.
HatangChat
Entry point of the SDK. Call configure once at startup, then open a chat, identify the user and listen to events.
HatangChatController
A ChangeNotifier over the engine for widgets: exposes state and the composer actions. One controller per visible conversation view.
HatangChatInbox
The visitor's conversations, newest activity first: who answered, the last message, when, unread count and status. Tapping one opens it; "New message" opens the current conversation (or an empty one).
HatangChatLauncher
A floating chat button with an unread badge. Place it in a Stack above your content (or use it as a Scaffold.floatingActionButton with alignment: null). Tapping calls onPressed, or HatangChat.open.
HatangChatLocalizations
The chat strings for the current locale. Hosts may add HatangChatLocalizations.delegate to their app; the chat screen provides itself when none is found, so this is optional.
HatangChatScreen
The full chat screen: app bar with the site name and availability, the conversation and the composer. Push it yourself (go_router, Navigator) or call HatangChat.open(context).
HatangChatStrings
Every string the chat UI shows. Pass overrides to HatangChat.configure (strings: {HatangLocale.vi: HatangChatStrings.vi.copyWith(...)}).
HatangChatTheme
Colours and shapes of the chat UI, as a ThemeExtension so hosts can register it on their ThemeData or pass it to HatangChat.configure.
HatangClosed
The chat screen was dismissed.
HatangCommerce
How purchases started from chat cards are handled.
HatangConversationStatus
The conversation's status changed.
HatangConversationView
The conversation without a scaffold: banners, away notice, message list (or the pre-chat form) and the composer. Embed it under your own app bar or tab bar; HatangChatScreen wraps it in a full screen.
HatangConversion
A conversion the host may forward to its analytics.
HatangEvent
Something a host app may react to (HatangChat.instance.events).
HatangLogger
Where the SDK writes its logs. Pass one to HatangChat.configure; the default is HatangLogger.silent.
HatangMessageReceived
A message from the team, bot or system arrived.
HatangMessageSent
A message from this visitor was stored (echo, possibly from another device).
HatangOpened
The chat screen was shown.
HatangPalette
Colour palette (ported from the agent app's theme/tokens.ts).
HatangProtocolOutdated
The gateway no longer speaks this SDK's protocol version; ship an update.
HatangRadius
Corner radii.
HatangReady
Bootstrapped and authenticated; the conversation (if any) is loaded.
HatangSession
A read-only view of the session for hosts.
HatangSessionChanged
The visitor identity behind this session changed.
HatangSpacing
4-pt spacing scale.
HatangType
Type scale.
HatangUser
The identity a host app attaches to the visitor with identify.
InboxRow
One conversation in the inbox.
ItalicToken
Italic text.
KeyValueStore
A tiny async key/value store. The Flutter layer provides one backed by flutter_secure_storage (token) and one by shared_preferences.
LauncherConfig
How the launcher button looks: a preset icon or the site's own image, and an optional short label per language that turns it into a pill ("Hỗ trợ").
Limits
Size limits the gateway enforces.
LinkToken
A link.
MemoryKeyValueStore
In-memory store for tests and for hosts that opt out of persistence.
MessageCard
A rich card carried in MessageDto.metadata (kind + payload).
MessageDto
A chat message.
MessageRow
A message bubble.
MessagesPage
A page of timeline items.
MessageText
Renders formatMessage tokens as rich text: links open externally, **bold**, _italic_ and `code` are styled. Tap recognizers are disposed with the widget.
OrderCard
An order summary.
OrderCardItem
One line of an order.
PaidMarks
Orders and payments the timeline says are paid: an order_paid system message (metadata.order_id) or an order_paid event (data.order_id, data.payment_id). The payment card message is not updated live when the customer pays, so the card checks these too (see PaymentCard.isPaid).
PaymentCard
A payment request (VietQR).
PaymentQr
Finds the VietQR code of a payment card.
PaymentQrImage
A raster image (PNG, JPEG, GIF or WebP) served at qr_image_url.
PaymentQrPayload
The EMVCo string: the SDK encodes and draws the QR code itself.
PaymentQrSource
What a payment card draws its VietQR code from.
PendingMessage
An outgoing message that has no ack yet (or failed).
PendingRow
An outgoing message without an ack.
PendingUpload
The upload behind a pending attachment message.
ProductCard
A product carousel.
ProductCardItem
One product in a ProductCard.
QuickRepliesCard
Buttons under a bot message; tapping one sends its label.
ScreenInfo
The screen the app shows (the native counterpart of a page).
SiteConfig
Site settings the widget and SDK render from.
SystemRow
A system line (notice, handoff, rated).
TextToken
Plain text.
Timeline
The loaded window of a conversation.
TimelineItem
One row of a conversation: a message or an event.
TypingRow
The agent is typing.
UploadSource
A file the visitor is sending: its bytes, name and MIME type. Built by the SDK's pickers (or by the host) and handed to ChatEngine.attach.
VisitorAppInfo
Which registered app and build a visitor uses.
VisitorConversationDto
The visitor-safe view of one of their conversations (history list, conversation.update frames).
VisitorDto
The visitor (this app's user as the site sees them).

Enums

ChatPhase
Where the engine is in its life.
ConversationStatus
Conversation lifecycle status.
HatangAttachmentSource
Where an attachment comes from.
HatangChatThemeMode
How the chat picks light or dark.
HatangConnectionState
Socket connection state as exposed to hosts.
HatangConversionKind
Kinds of conversion the SDK reports.
HatangLocale
Languages the Hatang widget and SDK speak.
HatangLogLevel
Log severity.
HatangSessionChangeReason
Why the session changed.
LauncherIcon
The launcher's preset icon (dashboard: website settings → launcher button).
OfflineCapture
What the site asks for before a visitor writes while nobody is online.
PaymentQrFailure
Why no QR code could be found.
PushProvider
Push providers a device token can come from.
SenderType
Who wrote a message or caused an event.
SiteTheme
The site's preferred colour scheme.

Constants

hatangHitSize → const double
Minimum tap target.
hatangMinTouch → const double
Minimum height of a touch control without Material's tap-target padding (text fields): Android asks for 48 dp.
protocolVersion → const int
The wire protocol version this SDK speaks.
sdkVersion → const String
This SDK's version (sent in the User-Agent and the socket's client info).
uploadMimeTypes → const Set<String>
MIME types the gateway accepts (the same list as the server's upload allow-list).

Properties

hatangDefaultBaseUrl → Uri
The production gateway.
final

Functions

availabilityLabel(Availability av, HatangLocale locale, HatangChatStrings strings) → String
Header subtitle: online, or offline with the next opening time.
buildRows(ChatState state, HatangChatStrings strings, {DateTime? now}) → List<ChatRow>
Rows for state: day separators, greeting when empty, notice / handoff / rated events only, "Seen" under the last read own message, sender names for the team, pending bubbles and the typing indicator.
cardBubbleText(String content, MessageCard? card, {String? intro}) → String
The text to show in the bubble above card, given the message content.
cardOf(Json? metadata) → MessageCard?
Port of cardOf from @hatang/chat-protocol: the card in metadata, if any.
dayLabel(DateTime at, HatangLocale locale, HatangChatStrings strings, {DateTime? now}) → String
"Today", "Yesterday" or the date, for a day separator.
formatMessage(String text) → List<FormatToken>
Tokenises text: links, **bold**, _italic_, `code` and line breaks. HTML is never interpreted.
mimeTypeForName(String name) → String?
MIME type for a file name, from its extension; null when the gateway would refuse it.
money(num value, String currency, HatangLocale locale) → String
Money in currency: đồng gets vnd, everything else 1,234.56 USD.
number(num value, HatangLocale locale, {int decimals = 0}) → String
Groups digits: 1.234.567 (vi) or 1,234,567 (en); at most decimals fraction digits.
pickLocale({String? preferred, String siteDefault = 'auto', String? deviceLanguage}) → HatangLocale
Locale resolution (same rule as the web widget and the agent app): explicit preferred → site default unless auto → device language starting with en → English, everything else Vietnamese.
plainTextOf(List<FormatToken> tokens) → String
The plain text of tokens (labels for links, no markers).
previewOf(String text, [int max = 200]) → String
Plain-text preview (one line, trimmed, at most max characters).
timeOf(DateTime at) → String
HH:mm in local time (both locales use 24-hour clocks here).
vnd(num value, [HatangLocale locale = HatangLocale.vi]) → String
Vietnamese đồng: 1.234.567 ₫.

Typedefs

HatangAvailability = Availability
The name hosts see for Availability (HatangChat.instance.availability).
HatangFilePick = Future<UploadSource?> Function()
Lets the visitor pick a file of any type, or null when they cancel.

Exceptions / Errors

HatangException
An error reported by the Hatang gateway (REST or socket) or by the SDK itself.
PaymentQrException
Thrown by PaymentQr.resolve.