flutter_crashlytics 0.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 91

flutter_crashlytics

Flutter plugin to enable Crashlytics reporting.

Setup

Android

To setup Crashlytics on Android side, you need to set under your manifest the Fabric ID like:

 <meta-data
            android:name="io.fabric.ApiKey"
            android:value="YOUR_ID_HERE" />

You also need to change you build.gradle file like:

buildscript {
    repositories {
        ...
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        ...
    }
}

And apply the fabric plugin apply plugin: 'io.fabric'

Nothing more.

iOS

On iOS side your need to set your Fabric ID under your Info.plist like:

<key>Fabric</key>
    <dict>
        <key>APIKey</key>
        <string>YOUR_ID_HERE</string>
        <key>Kits</key>
        <array>
            <dict>
                <key>KitInfo</key>
                <dict/>
                <key>KitName</key>
                <string>Crashlytics</string>
            </dict>
        </array>
    </dict>

Then on your Podfile add use_frameworks!

Don't forget to add your Run Script step on the build phases tab: ios run script

That's it :)

Flutter

All you need to do under your code is to let the plugin handle the Flutter crashes.

Your main method should look like:

void main() {
  bool isInDebugMode = false;

  FlutterError.onError = (FlutterErrorDetails details) {
    if (isInDebugMode) {
      // In development mode simply print to console.
      FlutterError.dumpErrorToConsole(details);
    } else {
      // In production mode report to the application zone to report to
      // Crashlytics.
      Zone.current.handleUncaughtError(details.exception, details.stack);
    }
  };

  runZoned<Future<Null>>(() async {
    runApp(MyApp());
  }, onError: (error, stackTrace) async {
    // Whenever an error occurs, call the `reportCrash` function. This will send
    // Dart errors to our dev console or Crashlytics depending on the environment.
    await FlutterCrashlytics().reportCrash(error, stackTrace, forceCrash: false);
  });
}

forceCrash allow you to have a real crash instead of the red screen, in that case the exception will tagged as fatal

API available

  • Add log to crash reporting with log(String msg, {int priority, String tag})
  • Add manual log to crash reporting with logException(Error/Exception exception, Stacktrace stack)
  • Add user info to crash reporting with setUserInfo(String identifier, String email, String name)
  • Add general info to crash reporting with setInfo(String key, dyncamic value)

Limitation

This plugin uses Crashlytics sdk to log manually dart crashes, all manual logged crashes are tagged as non fatal under Crashlytics, that's a limitation of the SDK.

You can bypass that limitation with the forceCrash parameter, instead of the red screen an actual crash will append, the crash will be tagged as Fatal.

On iOS fatal crash has there dart stacktrace under the Logs tab of Crashlytics, that's a limitation of iOS that prevent developers to set a custom stacktrace to an exception.

Contribution

We love contributions! Don't hesitate to open issues and make pull request to help improve this plugin

0.0.6

  • add manual log for Error/Exception
  • support for Zone

0.0.5

  • fix empty crash report in release mode.

0.0.4

  • add ability to force a crash when a flutter exception append to force a fatal error.

0.0.3

  • update package info.

0.0.2

  • enable SDK dart 2.

0.0.1

  • initial release.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_crashlytics/flutter_crashlytics.dart';

void main() {
  bool isInDebugMode = false;

  FlutterError.onError = (FlutterErrorDetails details) {
    if (isInDebugMode) {
      // In development mode simply print to console.
      FlutterError.dumpErrorToConsole(details);
    } else {
      // In production mode report to the application zone to report to
      // Crashlytics.
      Zone.current.handleUncaughtError(details.exception, details.stack);
    }
  };

  runZoned<Future<Null>>(() async {
    runApp(MyApp());
  }, onError: (error, stackTrace) async {
    // Whenever an error occurs, call the `reportCrash` function. This will send
    // Dart errors to our dev console or Crashlytics depending on the environment.
    debugPrint(error.toString());
    await FlutterCrashlytics().reportCrash(error, stackTrace, forceCrash: false);
  });
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Center(
              child: RaisedButton(
                onPressed: () {
                  final crash = List()[222];
                  debugPrint(crash);
                },
                child: Text('Crash'),
              ),
            ),
            Center(
              child: RaisedButton(
                onPressed: () {
                  try {
                    final crash = List()[555];
                    debugPrint(crash);
                  } catch (error) {
                    debugPrint(error.toString());
                    FlutterCrashlytics().logException(error, error.stackTrace);
                  }
                },
                child: Text('Manual error log'),
              ),
            ),
            Center(
              child: RaisedButton(
                onPressed: () {
                  try {
                    throw new FormatException();
                  } catch (exception, stack) {
                    debugPrint(exception.toString());
                    FlutterCrashlytics().logException(exception, stack);
                  }
                },
                child: Text('Manual exception log'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_crashlytics: ^0.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_crashlytics/flutter_crashlytics.dart';
  
Version Uploaded Documentation Archive
0.0.6 Sep 18, 2018 Go to the documentation of flutter_crashlytics 0.0.6 Download flutter_crashlytics 0.0.6 archive
0.0.5 Sep 14, 2018 Go to the documentation of flutter_crashlytics 0.0.5 Download flutter_crashlytics 0.0.5 archive
0.0.4 Aug 22, 2018 Go to the documentation of flutter_crashlytics 0.0.4 Download flutter_crashlytics 0.0.4 archive
0.0.3 Aug 21, 2018 Go to the documentation of flutter_crashlytics 0.0.3 Download flutter_crashlytics 0.0.3 archive
0.0.2 Aug 21, 2018 Go to the documentation of flutter_crashlytics 0.0.2 Download flutter_crashlytics 0.0.2 archive
0.0.1 Aug 21, 2018 Go to the documentation of flutter_crashlytics 0.0.1 Download flutter_crashlytics 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3
  • Flutter: 0.8.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

Package is pre-v0.1 release.

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Format lib/flutter_crashlytics.dart.

Run flutter format to format lib/flutter_crashlytics.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
stack_trace ^1.9.3 1.9.3
Transitive dependencies
collection 1.14.11
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8