bugsee_flutter 4.0.0 copy "bugsee_flutter: ^4.0.0" to clipboard
bugsee_flutter: ^4.0.0 copied to clipboard

outdated

Bugsee is a mobile SDK that adds crucial information to your bug and crash reports incuding video, network traffic, console logs and many other important traces from your app.

example/lib/main.dart

/// This is a sample Flutter app  that demonstrates how to catch various kinds
/// of errors in Flutter apps and report them to Bugsee.

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';

// This imports the Bugsee plugin
import 'package:bugsee_flutter/bugsee.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void onBugseeLifecycleEvent(BugseeLifecycleEventType e) {
  print(e);
}

Future<BugseeLogEvent> onBugseeLogEvent(BugseeLogEvent logEvent) {
  logEvent.text = "Filtered: " + logEvent.text;
  return Future.value(logEvent);
}

Future<BugseeNetworkEvent> onBugseeNetworkEvent(BugseeNetworkEvent e) {
  e.url = "<redacted>";
  return Future.value(e);
}

Future<List<BugseeAttachment>> onBugseeAttachmentsRequest(BugseeReport report) {
  var attachments = <BugseeAttachment>[];
  var list = utf8.encode("This is the contents of the attachment!");
  var data = list is Uint8List ? list : Uint8List.fromList(list);
  attachments.add(BugseeAttachment("testAttachment", "", data));
  return Future.value(attachments);
}

Future<void> configureBugsee() async {
  Bugsee.setLogFilter(onBugseeLogEvent);
  Bugsee.setNetworkFilter(onBugseeNetworkEvent);
  Bugsee.setLifecycleCallback(onBugseeLifecycleEvent);
  Bugsee.setAttachmentsCallback(onBugseeAttachmentsRequest);

  var bgColor = Color.fromARGB(255, 100, 150, 180);

  await Bugsee.appearance.iOS.setReportBackgroundColor(bgColor);
  await Bugsee.appearance.android.setReportBackgroundColor(bgColor);
}

BugseeLaunchOptions? createLaunchOptions() {
  if (Platform.isAndroid) {
    var options = AndroidLaunchOptions();
    // You can set Android-specific options here
    return options;
  }

  if (Platform.isIOS) {
    var options = IOSLaunchOptions();
    // You can set iOS-specific options here
    return options;
  }

  return null;
}

String getApplicationToken() {
  return Platform.isAndroid
      ? '<android-app-token>'
      : (Platform.isIOS ? '<ios-app-token>' : '');
}

Future<void> launchBugsee(
    void Function(bool isBugseeLaunched) appRunner) async {
  var launchOptions = createLaunchOptions();

  // Set all the required launch options to the desired state

  await Bugsee.launch(getApplicationToken(),
      appRunCallback: appRunner, launchOptions: launchOptions);
}

Future<void> main() async {
  // This is required to let Bugsee intercept network requests
  HttpOverrides.global = Bugsee.defaultHttpOverrides;

  await launchBugsee((bool isBugseeLaunched) async {
    if (isBugseeLaunched) {
      await configureBugsee();
    }
    runApp(const CrashyApp());
  });
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Crashy',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Crashy'),
      ),
      body: SingleChildScrollView(
          child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              child: Text('Dart exception'),
              onPressed: () {
                throw StateError('This is a Dart exception.');
              },
            ),
            ElevatedButton(
              child: Text('async Dart exception'),
              onPressed: () async {
                foo() async {
                  throw StateError('This is an async Dart exception.');
                }

                bar() async {
                  await foo();
                }

                await bar();
              },
            ),
            ElevatedButton(
              child: Text('Java exception'),
              onPressed: () async {
                Bugsee.testExceptionCrash();
              },
            ),
            ElevatedButton(
              child: Text('Handled exception'),
              onPressed: () async {
                try {
                  throw FormatException('Expected at least 1 section');
                } catch (ex, st) {
                  Bugsee.logException(ex, st);
                }
              },
            ),
            ElevatedButton(
              child: Text('Handled empty exception'),
              onPressed: () {
                Bugsee.logException(
                    StateError(
                        'This is a Dart exception with empty stack trace.'),
                    '');
              },
            ),
            BugseeSecureView(
                enabled: true,
                child: ElevatedButton(
                  child: Text('Log messages'),
                  onPressed: () {
                    print("This is a message posted with print() call");
                    Bugsee.log("This is a test console message");
                    Bugsee.log("This is a test console ERROR message",
                        BugseeLogLevel.error);
                    Bugsee.log("This is a test console DEBUG message",
                        BugseeLogLevel.debug);
                    Bugsee.log("This is a test console INFO message",
                        BugseeLogLevel.info);
                    Bugsee.log("This is a test console WARNING message",
                        BugseeLogLevel.warning);
                  },
                )),
            ElevatedButton(
              child: Text('Network request'),
              onPressed: () async {
                // var httpClient = HttpClient();
                // var request = await httpClient.getUrl(
                //     Uri.parse('https://jsonplaceholder.typicode.com/posts'));
                // var response = await request.close();
                // var responseBody =
                //     await response.transform(utf8.decoder).join();

                var response = await http.post(
                  Uri.parse('https://reqres.in/api/users'),
                  headers: <String, String>{
                    'Content-Type': 'application/json; charset=UTF-8',
                  },
                  body: jsonEncode(<String, String>{
                    'title': 'Some fancy title',
                  }),
                );
                var responseBody = response.body;

                print('Received network response. Length: ' +
                    responseBody.length.toString());
              },
            ),
            ElevatedButton(
              child: Text('Custom events'),
              onPressed: () async {
                Map<String, dynamic> params = <String, dynamic>{};
                params['string'] = 'test';
                params['int'] = 5;
                params['float'] = 0.55;
                params['bool'] = true;
                Bugsee.event('event', params);
                Bugsee.trace('number', 5);
                Bugsee.trace('float', 0.55);
                Bugsee.trace('string', 'test');
                Bugsee.trace('bool', true);
                Bugsee.trace('map', params);
                Bugsee.setAttribute('age', 36);
                Bugsee.setAttribute('name', 'John Doe');
                Bugsee.setAttribute('married', false);
              },
            ),
            ElevatedButton(
              child: Text('Show report dialog'),
              onPressed: () {
                Bugsee.showReportDialog('Test summary', 'Test description');
              },
            ),
            TextField(
                obscureText: true,
                decoration: InputDecoration(
                  labelText: 'Password',
                  border: OutlineInputBorder(),
                )),
            ElevatedButton(
              child: Text('Upload report'),
              onPressed: () {
                Bugsee.upload('Test summary', 'Test description');
              },
            ),
            ElevatedButton(
              child: Text('Show Feedback'),
              onPressed: () {
                Bugsee.showFeedbackUI();
              },
            ),
            ElevatedButton(
              child: Text('Add secure rect'),
              onPressed: () {
                Bugsee.addSecureRect(Rectangle(20, 20, 100, 100));
              },
            ),
            ElevatedButton(
              child: Text('Get all secure rects'),
              onPressed: () async {
                dynamic rects = await Bugsee.getAllSecureRects();
                print(rects);
              },
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
            ElevatedButton(
              child: Text('Dummy button'),
              onPressed: () async {},
            ),
          ],
        ),
      )),
    );
  }
}
5
likes
65
points
5.78k
downloads

Publisher

verified publisherbugsee.com

Weekly Downloads

Bugsee is a mobile SDK that adds crucial information to your bug and crash reports incuding video, network traffic, console logs and many other important traces from your app.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

unknown (license)

Dependencies

convert, crypto, flutter, stack_trace, uuid

More

Packages that depend on bugsee_flutter

Packages that implement bugsee_flutter