Flutter SDK
The Snapbug Flutter SDK provides a Dart bridge to the native Snapbug Android SDK, enabling network inspection, analytics monitoring, and crash reporting from your Flutter app.
Requirements
- Flutter >= 3.3.0
- Dart >= 3.5.4
- Dio >= 5.0.0 (for network interception)
- Android minSdk 24
Installation
Add the dependency to your pubspec.yaml:
dependencies:
snapbug_flutter: ^1.0.0Then run:
flutter pub getOr install directly from the command line:
flutter pub add snapbug_flutterQuick Start
Initialize Snapbug with the plugins you need:
import 'package:snapbug_flutter/snapbug_flutter.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Snapbug.start(
plugins: [
SnapbugNetwork(),
SnapbugAnalytics(),
SnapbugCrashReporter(),
],
);
runApp(const MyApp());
}Network Inspection
With Dio
Add the SnapbugDioInterceptor to your Dio client:
import 'package:dio/dio.dart';
import 'package:snapbug_flutter/snapbug_flutter.dart';
final dio = Dio();
dio.interceptors.add(SnapbugDioInterceptor());All HTTP requests made through this Dio instance will appear in the Snapbug Desktop network inspector.
Manual Logging
For HTTP clients other than Dio, you can log requests and responses manually:
SnapbugNetwork.logRequest(
method: 'GET',
url: 'https://api.example.com/users',
headers: {'Authorization': 'Bearer token'},
);
SnapbugNetwork.logResponse(
url: 'https://api.example.com/users',
statusCode: 200,
headers: {'content-type': 'application/json'},
body: '{"users": []}',
duration: Duration(milliseconds: 150),
);Analytics
Log analytics events with a source identifier:
Snapbug.analytics('firebase').logEvents([
AnalyticsEvent(
name: 'screen_view',
params: {'screen_name': 'Home'},
),
AnalyticsEvent(
name: 'button_click',
params: {'button_id': 'sign_up'},
),
]);You can use any string as the source identifier to group events (e.g., firebase, amplitude, mixpanel).
Crash Reporter
Automatic Fatal Error Capture
Wrap your app entry point to catch fatal errors:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Snapbug.start(
plugins: [SnapbugCrashReporter()],
);
SnapbugCrashReporter.catchFatalErrors(() {
runApp(const MyApp());
});
}Manual Error Reporting
Report caught exceptions manually:
try {
await riskyOperation();
} catch (error, stackTrace) {
SnapbugCrashReporter.reportError(
error: error,
stackTrace: stackTrace,
);
}Architecture
The Flutter SDK follows a bridge architecture:
Flutter (Dart)
|
v
Platform Channel (Method Channel)
|
v
Native Snapbug SDK (Android)
|
v
WebSocket/HTTP --> Snapbug Desktop
Dart calls are forwarded to the native Snapbug Android SDK, which handles the WebSocket connection to the Desktop app.
The Flutter SDK currently supports Android only. iOS support will be added in a future release.
Example App
A complete Flutter example app is available at SnapbugFlutter/example/ in the repository.
To run it:
cd SnapbugFlutter/example
flutter runTo build the APK:
cd SnapbugFlutter/example
flutter build apk --debugNext Steps
- Connect your device to the Desktop app
- Troubleshooting for common issues