Flutter
التثبيت
flutter pub add heysada_sanad
شرح الاستخدام أدناه بالإنجليزية، كما يظهر في سجل الحزمة، والشيفرة نفسها في كل لغة.
In-app support for Flutter apps (plan §7B, design, task 091). Your Help button opens a native sheet. If the app has help articles, the assistant answers from them. Otherwise, or when the user asks, the contact form opens: the user writes, sees a screenshot of the screen they were on, hides or removes anything, and presses Send. The message becomes a ticket in desk.
The web SDK (Web) behaves the same way. Both speak desk-support’s /sdk/v1.
Use it
dependencies:
heysada_sanad: ^0.1.0 # each brand's package, built with its name (config/brands.json, task 102)
void main() {
AppSupport.configure(const AppSupportOptions(
appKey: 'pk_…', // desk → Support apps → keys (publishable)
apiUrl: 'https://support.example.com', // where desk-support serves /sdk/v1
appVersion: '4.2.0',
));
runApp(const AppSupportScope(child: MyApp())); // above MaterialApp, so the capture sees every route
}
// your own help button:
IconButton(icon: const Icon(Icons.help_outline), onPressed: () => AppSupport.open(context));
Ways in: shake, screenshot, the floating launcher
Besides your own help button, the SDK can listen for the ways in the standard support SDKs offer. Each one is off until you switch it on at configure time:
AppSupport.configure(const AppSupportOptions(
appKey: 'pk_…',
apiUrl: 'https://support.example.com',
invocations: SupportInvocations(
shake: true, // a small chooser: Report a problem / Get help
shakeAction: ShakeAction.chooser, // or ShakeAction.contact: straight to the form
screenshot: true, // after a screenshot: "Need help with what's on screen?"
launcher: true, // the floating button with the unread badge
),
));
- Shake reads the accelerometer through
sensors_plus. Two readings over 2.7 g within half a second count as one shake, and nothing fires again for 1.5 s. The SDK stops listening while the app is in the background. - Screenshot taken comes from the plugin’s own channel:
ScreenCaptureCallbackon Android 14 and later (the plugin’s manifest declaresDETECT_SCREEN_CAPTURE, a normal permission), anduserDidTakeScreenshotNotificationon iOS. Android 13 and earlier have no such event, so there is no prompt there. The prompt doesn’t block the screen and goes after 6 s. The system’s screenshot is never read. The SDK takes its own capture right away, masked like every other one. - The floating launcher sits at the end side (the right, or the left in Arabic). The user can
drag it, and when they let go it snaps to the nearer side edge, at that height, on every screen.
It shows the unread badge and steps aside while Support is open. Use
AppSupport.hideLauncher()andshowLauncher()for a screen where it would be in the way.AppSupport.unread(aValueListenable<int>) andAppSupport.unreadCount()feed a badge of your own, and you can placeSupportLauncheryourself too. - The launcher and the prompt are drawn beside the part
AppSupportScopecaptures, so neither is ever in a screenshot.SupportMaskkeeps covering what it marks. - The web SDK has no shake and no screenshot event, because a browser tells a page about neither.
Opening from a failure: topic and attributes
AppSupport.open(
context,
topic: 'payment_failed',
attributes: {'order_id': order.id, 'error_code': e.code, 'amount': 12.5},
message: 'My payment didn't go through', // the form starts with it; the user can change it
);
The team sees the topic and attributes with the conversation. They are not sent to the corpus.
They are also listed under the form (“Details from the app, sent too: …”), so the user sees what
goes. Keys are snake_case (at most 40 characters). Values are flat: text (at most 256), a number,
or true/false. At most 20 are sent, and anything else is left out with a log line, never a throw.
Conversations, messages from the team, and call-backs (task 108)
// after sign-in: your own opaque id for the user (never an email, a name or a device id)
await AppSupport.identify('u-8812');
// on sign-out
await AppSupport.identify(null);
// the user's conversations with the team, or one of them
AppSupport.openConversations(context);
AppSupport.openConversation(context, conversationId);
// look for a message from the team now (the SDK also does it on its own, below)
final shown = await AppSupport.checkMessages(context);
// optional: name your root navigator, where the team's message is shown
runApp(AppSupportScope(navigatorKey: navigatorKey, child: MyApp(navigatorKey: navigatorKey)));
- Two-way conversations. Every message the user sends becomes a conversation they can follow in the app: the list (newest first, open or closed), and each thread with the user’s messages on the end side and the team’s on the start side, each labelled: a person on the team (the team’s name), the assistant (automated), or a notice from the system. The user replies from the thread; replying reopens a closed conversation. Open screens refresh every 15 seconds while the app is in the foreground, pull to refresh any time, and a closed thread stops refreshing.
- A message from the team, shown once. When desk opens a conversation with the user on its own
(say, an error hit them, which the errors product reports), the SDK shows a small banner, “We
noticed a problem”, over your screen without blocking it. It opens the thread, and it closes by
itself after 20 seconds. The SDK looks when the app starts, when it comes back to the foreground,
and after
identify(). Each conversation shows once (the ids go inSharedPreferences,support.proactive.seen). With no identified user, nothing is looked up at all. - The identified user (
identify, the core’s identity, kept assupport.user) goes with every message and call-back asuser_id, and lets desk reach them here. Conversations are bound to the install (support.install): another install never sees them, whatever user id it names. A device with no storage has no install id, so it makes no conversation call. - Call-back. From the form, “Request a call-back” asks for the number with its country code (sent as E.164; Arabic digits work), what the call is about, and an optional preferred time. It is never queued offline: a phone number is not written to storage.
- A person stays in reach. Under the help assistant’s answers, “Talk to a person” is always there, whatever the assistant said, and an automated answer in a thread says a person on the team will see a reply.
- Arabic. Every new screen, the banner and the call-back form follow the language and read right to left; phone numbers stay left to right.
The calls, all with X-App-Key and X-App-Install: GET /sdk/v1/conversations?user_id=,
GET /sdk/v1/conversations/{id}, POST /sdk/v1/conversations/{id}/messages,
POST /sdk/v1/callbacks, and user_id on POST /sdk/v1/tickets.
Setup notes
- Wrap the app once in
AppSupportScope, aboveMaterialApp. Without it, Support still opens, but with no screenshot. - Mark what must never leave the device with
SupportMask(child: …)(card numbers, balances, personal details). Masked widgets, obscured text fields (obscureText: true) and platform views (WebViews, maps: they can’t be drawn into the image) are blacked out before the user sees the preview. - Android: the app needs the
INTERNETpermission, as any networked app does. - iOS: a thread’s image button opens the photo library (
image_picker): addNSPhotoLibraryUsageDescriptiontoInfo.plist(App Store review asks for it). - The language follows
AppSupportOptions.language, then the app’s locale (aroren), then the app’s first language. Arabic is fully right to left.
What it does, and what it never does
- It never opens itself and never throws into your app.
open()completes quietly. Problems go todebugPrint. A second tap while Support is opening or open does nothing.AppSupport.close()closes it. - One still image of your app, taken with
RepaintBoundary.toImage()the moment Support opens, before the sheet is drawn. It needs no permission and has no system prompt. It never shows other apps, the status bar or the keyboard. It is at most 2× and 4096 px on a side. The user can hide parts (burned into the pixels), remove it, or attach it (theaskmode). What the preview shows is exactly what is uploaded. - The image lives in memory only. It is never written to disk. When the service is unreachable, the
message (text only) is queued in
SharedPreferences: at most 5 messages, for up to 3 days. They are sent at the nextconfigure()oropen(), or when the app comes back to the foreground. The form tells the user the message will go without the screenshot. - The help assistant answers only from your articles and names the ones it used. When it can’t answer, it says so, and “Didn’t help?” moves the user to the form with the conversation attached. The user can untick it. “Talk to a person” stays under every answer.
- Only the allowlisted context is sent: app version, build, OS name and major version, phone or tablet, and the language. The form lists it under the message.
- The install id (
support.install, random) is used for rate limits, and to keep a user’s conversations to the install they were written from.
Your privacy policy: template
When you contact support in this app, we send your message, and, if you leave them attached, a screenshot of the screen you were on and your conversation with our help assistant. We also send the app version, the operating system and the device type. You see all of it before you press Send. If you are signed in, your account id goes with it, so our replies and our messages to you (for example, when we notice a problem that affected you) reach you in the app. If you ask us to call you, we send the number you give and what the call is about. Support messages are kept for 180 days after they are resolved.
Develop
This package is built on the shared SDK core (../core): the transport, the offline
queue, the store and the install id. The core is a dependency (heysada_core when shipped, ADR
034); the view renderer (../ui) is vendored, so lib/src/ui/ is a generated copy
(git-ignored). Edit the originals, then run ../check.sh, which copies the renderer in and runs
format, flutter analyze and flutter test here. ../build.py dist builds
the package each brand ships, under the name config/brands.json gives it.
The drift gate is test/wire_test.dart: every key the SDK sends must be in desk-support’s
openapi.json, which refuses unknown keys. It runs again whenever desk-support changes
(scripts/check-projects.sh).
On a device: e2e/serve.py runs the real desk-support on a scratch database in the service’s test
stack. example/ is a host app to drive against it, and
apps/demo-flutter is one with every product’s SDK in it.
The app’s design (ADR 031, task 419)
Support is drawn from the app’s design. The contact form is desk’s sheet_view, drawn with the
app’s design bundle (GET /sdk/v1/design/bundle, kept with its ETag and asked again every minute
while the sheet is up; a failed read keeps the last one). Its message and email fields and
send send the ticket (once, however often Send is pressed), and close closes the sheet. The
screenshot and its tools, the conversation kept, the conversations, the call-back, the assistant
and the done screen are drawn around it in the design’s colours (uiThemeData). desk sends no theme: the design is the one source of the look.
Offline, the saved design. The last config desk answered (per app and language) and the last bundle read are kept on the device. Offline, or while desk is down, the sheet draws that form with that design, says it is offline, and queues what is sent. With nothing saved (or only another language’s form) it says Support can’t be reached, never a form drawn another way; so do the conversations, which aren’t shown without a design.
desk fills the form’s header with the team as the app’s design says (brand.name, else the team
name, else the app’s name) and the brand’s https:// logo. The assistant’s header and a thread name
the team the same way.