sdkflutter

Flutter SDK

Add ScryWatch to your Flutter app for mobile log monitoring, session tracking, and crash reporting — with automatic device detection.

Flutter SDK

The ScryWatch Flutter SDK adds log monitoring and session tracking to your iOS and Android apps. It automatically detects device type and manages session IDs for you.

What you’ll need

Step 1: Add the dependency

In your pubspec.yaml:

dependencies:
  scrywatch: ^1.0.0

Then run:

flutter pub get

Step 2: Initialize the SDK

In your main.dart, initialize ScryWatch before runApp:

import 'package:scrywatch/scrywatch.dart';

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

  await ScryWatch.initialize(
    apiKey: 'sw_your_api_key_here',
    service: 'my-flutter-app',
    environment: 'production',
  );

  runApp(MyApp());
}

The SDK automatically detects the device type (mobile), OS, and app version from the Flutter environment.

Step 3: Log events

// Info level
ScryWatch.info('User signed in', metadata: {'userId': '1234'});

// Warning level
ScryWatch.warn('Low memory warning', metadata: {'available_mb': 45});

// Error level
ScryWatch.error('Payment failed', metadata: {'orderId': 'ord_abc', 'reason': 'card_declined'});

All events are batched and sent automatically. You don’t need to manage flushing manually.

Step 4: Track user sessions

The SDK generates a session ID automatically at app launch and rotates it after 30 minutes of inactivity.

To associate a session with a specific user:

// Set user ID for all subsequent events
ScryWatch.setUser('user_1234');

// Clear user when they log out
ScryWatch.clearUser();

Session events appear on the Sessions page in the dashboard.

Step 5: Track navigation

In your route observer, add navigation tracking:

class ScryWatchNavigatorObserver extends NavigatorObserver {
  @override
  void didPush(Route route, Route? previousRoute) {
    ScryWatch.info('Screen viewed', metadata: {
      'screen': route.settings.name,
      'previous': previousRoute?.settings.name,
    });
  }
}

Register the observer in your MaterialApp:

MaterialApp(
  navigatorObservers: [ScryWatchNavigatorObserver()],
  ...
)

Step 6: Capture Flutter errors

Capture unhandled Flutter errors and send them to ScryWatch:

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

  FlutterError.onError = (FlutterErrorDetails details) {
    ScryWatch.error(
      'Flutter error: ${details.exceptionAsString()}',
      metadata: {'stack': details.stack.toString()},
    );
  };

  await ScryWatch.initialize(apiKey: 'sw_your_api_key_here');
  runApp(MyApp());
}

Tip: Combine Flutter error capture with zone-based Dart error catching for complete coverage of both Flutter framework errors and async Dart errors.

Step 7: Capture async Dart errors

runZonedGuarded(() async {
  await ScryWatch.initialize(apiKey: 'sw_your_api_key_here');
  runApp(MyApp());
}, (error, stackTrace) {
  ScryWatch.error(
    'Unhandled error: $error',
    metadata: {'stack': stackTrace.toString()},
  );
});

You’re done

You now know how to:

Full Flutter SDK reference — constructor options, session management API, and automatic device detection fields.

API Reference

Want the full API spec for this feature?

View in Docs →
← All guides