emitrace 1.3.0 copy "emitrace: ^1.3.0" to clipboard
emitrace: ^1.3.0 copied to clipboard

One-tap Flutter debugging toolkit that captures logs, route transitions, Dio network activity, errors, screenshots, and shareable bug reports.

example/lib/main.dart

import 'package:dio/dio.dart';
import 'package:emitrace/emitrace.dart';
import 'package:flutter/material.dart';
import 'logger_demo_page.dart';

final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();
final EmitraceRouteObserver _routeObserver = EmitraceRouteObserver();
final Dio _dio = Dio()..interceptors.add(EmitraceDioInterceptor());

void main() {
  // Development
  final emitraceConfig = Emitrace.initialize(
    mode: EmitraceMode.development,
  ).copyWith(
    appName: 'Emitrace Example',
    navigatorKey: _navigatorKey,
    enableReportGenerator: true,
    enableSlackIntegration: false,
    enableDiscordIntegration: false,
    slackWebHookUrl: '',
    discordWebhookUrl: '',
  );

  // QA/TestFlight
  // Emitrace.initialize(
  //   enabled: const bool.fromEnvironment(
  //     'EMITRACE_ENABLED',
  //     defaultValue: false,
  //   ),
  // );

  // Production
  // Emitrace.initialize(
  //   mode: EmitraceMode.production,
  // );

  runApp(ExampleApp(config: emitraceConfig));
}

class ExampleApp extends StatelessWidget {
  final EmitraceConfig config;
  const ExampleApp({super.key, required this.config});

  @override
  Widget build(BuildContext context) {
    return EmitraceScope(
      config: config,
      child: MaterialApp(
        navigatorKey: _navigatorKey,
        navigatorObservers: [_routeObserver],
        home: const ExampleHomePage(),
      ),
    );
  }
}

class ExampleHomePage extends StatelessWidget {
  const ExampleHomePage({super.key});

  Future<void> _safeFailingRequest() async {
    try {
      await _dio.get('https://httpstat.us/500');
    } catch (e, st) {
      await Emitrace.error(e, st, data: {'source': 'failing_request'});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Emitrace Example')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          const Text(
            'Pretty Logger',
            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
          ),
          const SizedBox(height: 8),
          ElevatedButton(
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute<void>(
                  settings: const RouteSettings(name: 'pretty_logger_demo'),
                  builder: (_) => const LoggerDemoPage(),
                ),
              );
            },
            child: const Text('Pretty Logger Demo'),
          ),
          const SizedBox(height: 16),
          ElevatedButton(
            onPressed: () {
              Emitrace.log(
                'Manual log from example',
                data: {'screen': 'home'},
              );
            },
            child: const Text('Emitrace.log'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              Emitrace.event(
                'checkout_started',
                data: {'cartItems': 3},
              );
            },
            child: const Text('Emitrace.event'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              Emitrace.action(
                'tap_primary_cta',
                data: {'cta': 'start_debug'},
              );
            },
            child: const Text('Emitrace.action'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () async {
              await _dio.get('https://jsonplaceholder.typicode.com/todos/1');
            },
            child: const Text('Dio Success Request'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: _safeFailingRequest,
            child: const Text('Dio Failing Request (500)'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () async {
              await Emitrace.captureScreenshot(reason: 'manual_example');
            },
            child: const Text('Capture Screenshot'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () async {
              await Emitrace.captureReport();
            },
            child: const Text('Generate Report'),
          ),
          const SizedBox(height: 10),
          const Text(
            'Open the Emitrace panel -> Logs tab for search + filters and Device tab for Debug Bundle, GitHub issue markdown, Crash summary, and Discord send action.',
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute<void>(
                  settings: const RouteSettings(name: 'details_page'),
                  builder: (_) => const DetailsPage(),
                ),
              );
            },
            child: const Text('Navigate to Details Page'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              throw StateError('Forced crash from example app');
            },
            child: const Text('Force Error'),
          ),
        ],
      ),
    );
  }
}

class DetailsPage extends StatelessWidget {
  const DetailsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Emitrace.breadcrumb('Back tapped from details page');
            Navigator.of(context).pop();
          },
          child: const Text('Go Back'),
        ),
      ),
    );
  }
}
18
likes
160
points
539
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

One-tap Flutter debugging toolkit that captures logs, route transitions, Dio network activity, errors, screenshots, and shareable bug reports.

Repository (GitHub)
View/report issues
Contributing

Topics

#flutter #debugging #logging #dio #qa

License

MIT (license)

Dependencies

dio, flutter, http, package_info_plus, path_provider, platform, share_plus

More

Packages that depend on emitrace