Mobile SDK

Error monitoring for Flutter

A Dart package that reports Flutter framework errors and uncaught async errors. The handlers are wired explicitly so you can compose them with your own.

Frameworks FlutterRequires Dart 3.0+Package errorgapSource ↗Package ↗Agent guide ↗
Install

Install

Add it to pubspec.yaml (or flutter pub add errorgap):

yaml
dependencies:
  errorgap: ^0.2.0
Configure

Configure

In main(), initialize and wire both error handlers:

dart
void main() {
  WidgetsFlutterBinding.ensureInitialized();

  Errorgap.init(ErrorgapConfiguration(
    endpoint:    'https://your-endpoint',
    projectSlug: 'your-project',
    apiKey:      const String.fromEnvironment('ERRORGAP_API_KEY'),
    environment: kReleaseMode ? 'production' : 'development',
  ));

  FlutterError.onError = (details) {
    Errorgap.notify(details.exception, stackTrace: details.stack);
    FlutterError.presentError(details);
  };

  PlatformDispatcher.instance.onError = (error, stack) {
    Errorgap.notify(error, stackTrace: stack);
    return true;
  };

  runApp(const MyApp());
}

Pass the key with --dart-define=ERRORGAP_API_KEY=... rather than hardcoding it.

Session replay

Session replay

Version 0.5.0 records session replay on iOS and Android. Mobile sessions are a timeline only — app start, screens, failed API calls, errors and backgrounding — with no screenshots. Whether anything is recorded is set per project in Errorgap under Settings → Session replay: nothing while replay is off, and a sampled share of sessions while it is on. Only sessions that hit an error are kept, and each opens from its error group or incident.

The package doesn't depend on Flutter, so call Errorgap.trackScreen(name) from a NavigatorObserver, Errorgap.appPaused() / appResumed() from an AppLifecycleListener, and send API calls through ErrorgapHttpClient — the README has the full snippet.

Trigger a test error

Trigger a test error

dart
ElevatedButton(
  onPressed: () => throw Exception('Errorgap test error'),
  child: const Text('Test Errorgap'),
)
Verify

Verify the connection

Confirm your key and endpoint reach errorgap before wiring anything else — send one event straight to the ingestion API:

bash
curl -sS -X POST "$ERRORGAP_ENDPOINT/api/projects/$ERRORGAP_PROJECT_SLUG/notices" \
  -H "content-type: application/json" \
  -H "x-errorgap-project-key: $ERRORGAP_API_KEY" \
  -d '{"errors":[{"type":"ErrorgapInstallTest","message":"Errorgap install verification"}]}'

A 201 with a group_id means ingestion works (202 = received but sampled; 401 = wrong key). Then trigger the test error above through the SDK. Your onboarding screen's Verify step checks the stack off automatically once the first event lands — it polls every three seconds.

Next: the full ingestion API, or browse every SDK.