Skip to main content

Flutter

info

A Flutter Sample app is available at Github Bugfender Flutter

We would like to express our gratitude to Tidhar Nitzan and Pol Batlló for their valuable contribution to this plugin. While we offer basic support for it, please note that the plugin is not officially supported. As a result, our ability to assist you may be limited at times. However, please don't hesitate to reach out with any specific questions or concerns, and we will do our best to help within the scope of our capabilities.

Check out ​https://pub.dartlang.org/packages/flutter_bugfender

Bugfender is a game-changing platform that logs every detail your users experience and feeds the data directly to an easy-to-use web console. Bugfender SDK is multi-platform and available for mobile and web apps, so you can use the same tool for all your apps.

Specifically for Flutter developers, Bugfender offers powerful capabilities to remotely monitor and debug any log or error. You can easily reproduce and fix issues using our detailed log viewer and the stack trace of exceptions.

If you don't have a Bugfender account yet, go to Bugfender Signup and come back here.

Install the Bugfender Plugin for Flutter

Open a command prompt at the root of the project folder and run the following command.

flutter pub add flutter_bugfender

This will add a line like this to your project: pubspec.yaml

dependencies:
flutter_bugfender: ^2.3.0

Now your editor may run an implicit flutter pub get command. You can run this explicitly from the command prompt as well.

Configure

To use the plugin and start logging activities to Bugfender, import the plugin to the main.dart file using the following line.

import 'package:flutter_bugfender/flutter_bugfender.dart';

And wrap your runApp statement like this:

void main() {
FlutterBugfender.handleUncaughtErrors(() async {
await FlutterBugfender.init("YOUR_APP_KEY_HERE",
enableCrashReporting: true, // these are optional, but recommended
enableUIEventLogging: true,
enableAndroidLogcatLogging: true);
FlutterBugfender.log("hello world!");
runApp(new MyApp());
});
}
note

Remember to change YOUR_APP_KEY_HERE with the app key of your app. You can get an app key by signing up to Bugfender. For all the available options see our reference.

Usage

Send logs

After the successful installation and configuration, you can now use our APIs in your Flutter application to send logs.

FlutterBugfender.log("Working fine!");

Similarly, the SDK provides other methods to send logs to the server:

FlutterBugfender.fatal("Fatal sent!");
FlutterBugfender.error("Error sent!");
FlutterBugfender.warn("Warning sent!");
FlutterBugfender.info("Info sent!");
FlutterBugfender.debug("Debug sent!");
FlutterBugfender.trace("Trace sent!");

Set Device Data

Once your application is running on several devices, it will be useful to know which device belongs to whom. You can associate information to a device as if it were a dictionary:

FlutterBugfender.setDeviceString("user.email", "[email protected]");
FlutterBugfender.setDeviceInt("user.id", 32);
FlutterBugfender.setDeviceFloat("user.pi", 3.14);
FlutterBugfender.setDeviceBool("user.enabled", true);

This will later on let you search this device by “key” in the Bugfender Dashboard and you can use any of the associated data to filter our your device list.

If you want to remove a data from the device, you can call removeDeviceKey:

FlutterBugfender.removeDeviceKey("user.pi");

Send Issues

Bugfender allows you to send issues to the server. An issue is similar to an exception but they are showed in the issues section and you can send issues any time from the app, even if the device is not enabled in the system. Issues are useful to keep track of important errors that you can detect in your code.

For sending an issue you can use the following function:

FlutterBugfender.sendIssue("Test Issue", "Issue value goes here!");

Send User Feedback

Getting feedback from the final users is one of the most important things for an app developer. Good user feedback allows you to detect errors in your app and helps you to understand better your product.

Sending User Feedback automatically sends all cached logs for the current session, even if the device is not enabled for sending logs.

Send feedback using your UI

You can send user feedback directly if you got the feedback with your own view controller. To send it, you should do like this:

FlutterBugfender.sendUserFeedback("Test user feedback", "User feedback details here!");

Built-in feedback modal

You can send user feedback with our ready-made UI like this:

FlutterBugfender.getUserFeedback(); // Show a screen which asks for feedback

Report Dart and Flutter Exceptions

To be able to report flutter exception you'll need to wrap runApp(new MyApp()) on your main function like this:

FlutterBugfender.handleUncaughtErrors(() async {
runApp(new MyApp());
});

Previous code is just a very basic example, if you need more control on your error handling, here there is an improved version of the error handling code:

// Capture Flutter Error
FlutterError.onError = (FlutterErrorDetails details) async {
FlutterError.presentError(details);
await FlutterBugfender.sendCrash(details.exception.toString(), details.stack?.toString() ?? "");
};
// Capture Dart Exceptions
runZonedGuarded(() {
runApp(new MyApp());;
}, (Object error, StackTrace stack) async {
await FlutterBugfender.sendCrash(error.toString(), stack.toString());
});

Advanced Usage

Send Logs with Tags

Bugfender has a more advanced logging system than sending regular logs, you can use the following method to add a tag will allow you find and filter logs easily in the Bugfender log viewer.

FlutterBugfender.sendLog(
line: 42,
method: "someMethod()",
file:"someFile",
level: LogLevel.info,
tag: "Custom tag",
text: "This is a custom log"
);

Having your app decide when to send logs

In some special circumstances you may want to send logs, regardless of the enabled state of the device in the Bugfender console, for example in a custom exception handler. Use forceSendOnce to force sending the logs once, and use setForceEnabled: to force it for some period of time.

FlutterBugfender.forceSendOnce();

FlutterBugfender.setForceEnabled(true);

Manually sending crashes

If you have your own crash reporting system and need to send crashes, you can do so by calling directly sendCrash

FlutterBugfender.sendCrash("Test Crash", "Stacktrace here!");

Sometimes you want to integrate Bugfender with a third party tool. For this purpose, the SDK provides a method that returns the URL for the session. You can send it to the third party tool to easily go to the logs of the current session from the other tool.

FlutterBugfender.getSessionUri();

Sometimes you want to integrate Bugfender with a third party tool. For this purpose, the SDK provides a method that returns the URL for the current device. You can send it to the third party tool and easily navigate back to the logs of the device from the other tool.

FlutterBugfender.getDeviceUri()

Using this package in a web project

The plugin assumes the Bugfender JS library is already loaded. You may load it by adding the following snippet to your index.html file:

<script src="https://js.bugfender.com/bugfender-v2.js"></script>