Flutter In development
The nabd_sdk package for Flutter 3.35 and later.
Not available yet. These examples show the planned API; package and function names may change before the first release.
Install
flutter pub add nabd_sdkOnce published. Network requests are measured automatically; you need nabd_dio only if your Dio uses the native system networking, or on the web.
Setup
import 'package:nabd_sdk/nabd_sdk.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Nabd.init(
orgToken: const String.fromEnvironment('NABD_KEY'),
appName: 'My App',
environment: 'production',
consentRequired: true,
);
runApp(const MyApp());
}If you set FlutterError.onError or PlatformDispatcher.onError, do it before Nabd.init; the SDK passes every error on to them.
endpoint is optional, for testing against a local server. The secret key nb_sec_… is rejected inside the app.
Consent
// after the user accepts the notice
await Nabd.setConsent(true);Screen names
MaterialApp(
navigatorObservers: [Nabd.observer],
routes: {'invoice_create': (_) => const InvoiceCreatePage()},
);GetMaterialApp(navigatorObservers: [Nabd.observer]);
// name the route explicitly: names derived from class names break with --obfuscate
Get.to(() => const InvoiceCreatePage(), routeName: 'invoice_create');GoRouter(
observers: [
NabdNavigatorObserver(nameResolver: (route) => route.settings.name),
],
routes: routes,
);
// or manually (tabs inside one screen, for example)
Nabd.trackScreen('invoice_create');Manual events
Nabd.trackEvent(NabdEvent.taskCompleted, screen: 'invoice_create');
Nabd.trackEvent(NabdEvent.errorShown, screen: 'invoice_create');
Nabd.startLoading('invoice_create');
try {
await repository.save(invoice);
} finally {
Nabd.stopLoading('invoice_create');
}
Nabd.setUserRef(userRefFromServer);Optional adapters
dio.interceptors.add(NabdDioInterceptor()); // status and duration onlyNabdIgnore(child: AmountKeypad())Captured automatically
- Rage taps, and taps on disabled buttons.
- Dart errors (type and fingerprint), and unexpected exits (estimated, sent on the next launch).
- Frames frozen for more than 700 ms in release builds.
- Network requests (
package:http, Dio and network images): connection failures, 5xx, and anything longer than 3 seconds. Status and duration only, and the same failure once per 10 seconds. - With every error, the last 10 steps. Turn it off with
errorTrail: false.
await Nabd.init(
orgToken: 'nb_pub_…',
appName: 'My App',
// captureNetwork: false, // turns off automatic network measurement
// ignoreRequests: [RegExp('/poll')], // replaces the default (SignalR and socket.io)
);Network measurement limits: not automatic on the web. Not covered: cronet_http and cupertino_http, and any HttpClient created before Nabd.init. If you set HttpOverrides.global yourself, do it before Nabd.init.
Support chat
With messages, your team can message a specific user from a ticket in the dashboard, and the user replies inside the app. Off by default; the floating button appears only when there is a message for them, after consent. You need setUserRef to open a ticket for them.
await Nabd.init(orgToken: 'nb_pub_…', appName: 'My App', messages: true);
MaterialApp(
navigatorObservers: [Nabd.observer],
builder: (context, child) => NabdMessages(child: child!),
);ValueListenableBuilder(
valueListenable: Nabd.conversations,
builder: (context, conversations, _) => SupportList(conversations),
);
Nabd.watchMessages(true); // while the conversation is open, false when it closes
final sent = await Nabd.replyToMessage(conversationId, text);
await Nabd.markMessagesRead(conversationId);- The app checks for messages when it opens or returns to the foreground, every two minutes, and every 15 seconds while the conversation is open. There is no notification while the app is closed.
- The interface is Arabic if the app language (
Localizations) is Arabic, and English otherwise. An app without localization settings counts as English. - The conversation and its taps are not counted as usage signals.
- The conversation is tied to this installation by a random secret stored on the device; another device of the same user does not see it, and a data deletion request changes the secret.
- Compute
user_refwith HMAC on your server, so a user cannot pretend to be someone else. - The reply field has no selection, copy or paste.
- On Android the back button does not close the panel; use the close button.
- The floating button may cover part of your UI at the bottom.
Message text is stored in Nabd for the retention period. Tell your users in your privacy policy, and add “Customer Support” to your App Store and Google Play disclosures.
Deletion and sending
await Nabd.requestDataDeletion();
await Nabd.setConsent(false);
await Nabd.flush();Review your App Store and Google Play disclosures: the SDK collects usage and diagnostic data and a random identifier.