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

bash
flutter pub add nabd_sdk

Once published. Network requests are measured automatically; you need nabd_dio only if your Dio uses the native system networking, or on the web.

Setup

lib/main.dart
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.

dart
// after the user accepts the notice
await Nabd.setConsent(true);

Screen names

MaterialApp
MaterialApp(
  navigatorObservers: [Nabd.observer],
  routes: {'invoice_create': (_) => const InvoiceCreatePage()},
);
GetX
GetMaterialApp(navigatorObservers: [Nabd.observer]);

// name the route explicitly: names derived from class names break with --obfuscate
Get.to(() => const InvoiceCreatePage(), routeName: 'invoice_create');
go_router or any other navigation
GoRouter(
  observers: [
    NabdNavigatorObserver(nameResolver: (route) => route.settings.name),
  ],
  routes: routes,
);

// or manually (tabs inside one screen, for example)
Nabd.trackScreen('invoice_create');

Manual events

dart
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 — package nabd_dio
dio.interceptors.add(NabdDioInterceptor()); // status and duration only
Exclude from rage taps
NabdIgnore(child: AmountKeypad())

Captured automatically

dart
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.

dart
await Nabd.init(orgToken: 'nb_pub_…', appName: 'My App', messages: true);

MaterialApp(
  navigatorObservers: [Nabd.observer],
  builder: (context, child) => NabdMessages(child: child!),
);
With your own UI (without NabdMessages)
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);

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

dart
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.