crashops_flutter 0.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 57

CrashOps plugin for Flutter #

License: MIT

This Flutter plugin helps to bridge your app with the CrashOps native SDK. CrashOps SDK helps you monitor your app's crashes and Flutter errors.

Installation #

⑂ & ▶ (plug n' play)

Easiest to install, all you need to do is add crashops_flutter dependency and the SDK will automatically start monitoring native crashes on each app launch.

Required changes in your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
...
  crashops_flutter: 0.2.03
...

Usage #

(see the a full example project in: github.com/CrashOps/Flutter-Example)

CrashOps can catch also errors from Flutter and Dart, not only native crashes. #

To catch errors from your Flutter app, edit your main() method as follows:

void main() {
  CrashOps.instance.run(
      app: MyApp(),
      iosKey: "your-ios-application-key-from-crashops",
      androidKey: "your-android-application-key-from-crashops",
      onError: (flutterErrorDetails, globalError, stackTrace) {
        if (flutterErrorDetails != null) {
          // Sometimes 'flutterErrorDetails' may be null because CrashOps catches Dart errors as well, not only Flutter errors.
          //
          // In case you wish to use more error catchers, make calls like this one:
          // Crashlytics.instance.recordFlutterError(flutterErrorDetails);
        }

        print("CrashOps caught an error from Flutter / Dart:\nError: $globalError\nStack Trace: $stackTrace");
      });
}

Customize configurations as you like #

class _MyAppState extends State<MyApp> {
  // It's not mandatory to put those configurations inside a State.
  // It may also be in the "main()" function.
  final CrashOps crashOps = CrashOps();

  ...

  @override
  void initState() {
    super.initState();

    // If you're willing to create logs in debug
    crashOps.isEnabledInDebugMode = true;
    // If you wish to upload logs to CrashOps' servers
    crashOps.setApplicationKey(
        iosKey: "your-ios-application-key-from-crashops",
        androidKey: "your-android-application-key-from-crashops");
    // If you wish to include more details in each log
    crashOps.setMetadata({"yo": "that's my awesome app!"});
  }

  ...

}

Configuration Files (use them if not configured programmatically) #

These files are not mandatory to use as you can also configure CrashOps via code only (programmatically, as mentioned above), but you still can add these files to save configuration via coding.

iOS 'plist' configuration file #

CrashOpsConfig-info.plist

Android 'xml' configuration file #

crashops_config.xml

Don't have Flutter yet? #

To help you getting started with Flutter, view their online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Acknowledgments #

Our iOS SDK uses KSCrash library.

Our Android SDK uses retrofit.

Thanks to this awesome framework called Flutter, we cloud export this package.

TODO #

Work in progress: creating a UI dashboard on the web, stay tuned.

0.0.1 #

  • First version ever - it's a plug n' play plugin that initiates our native SDK, CrashOps will simply wait for any app crash and will report on next app lunch. The client ID may be supplied via code or the config file (for more info see our docs).

0.0.2 #

  • Added plain test.

0.0.3 #

  • Improving plugin by following "pub.dev" analysis recommendations.

0.0.8 #

  • Updated README.

0.0.81 #

  • Fixed conflicts with Firestore in iOS.

0.0.82 #

  • Enabled app errors and Flutter errors.
  • Generating IPS files for iOS crash logs.
  • CrashOps will upload only compressed log files and avoid large requests.

0.0.820 #

  • Enabled app errors and Flutter errors.

0.0.825 #

  • Simplified the way we catch errors from Dart and from Flutter.
  • Updated docs.
  • Using an improved version of CrashOps Android SDK.

0.1.0 #

(all previous versions are deprecated) #

  • First official release! After testing this package for a few months now, in production, we can say that CrashOps is production ready.
  • Updated docs.
  • Simplified the way we catch Dart & Flutter errors.
  • Using our official releases of CrashOps iOS & Android SDKs.

0.1.11 #

  • Minor improvements.

0.2.01 #

  • Performance improvements.

0.2.03 #

  • Performance improvements.
  • Now the iOS SDK is smoother safer than the previous versions.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:crashops_flutter/crashops_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  CrashOps.instance.run(
      app: MyApp(),
      iosKey: "your-ios-application-key-from-crashops",
      androidKey: "your-android-application-key-from-crashops",
      onError: (flutterErrorDetails, globalError, stackTrace) {
        if (flutterErrorDetails != null) {
          // Sometimes 'flutterErrorDetails' may be null because CrashOps catches Dart errors as well, not only Flutter errors.
          //
          // In case you wish to use more error catchers, make calls like this one:
          // Crashlytics.instance.recordFlutterError(flutterErrorDetails);
        }

        print(
            "CrashOps caught an error from Flutter / Dart:\nError: $globalError\nStack Trace: $stackTrace");
      });
}

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

class _MyAppState extends State<MyApp> {
  final CrashOps crashOps = CrashOps();
  bool _isCrashOpsEnabled;
  String get _btnEnableTitle => _isCrashOpsEnabled ? "enabled" : "disabled";

  @override
  void initState() {
    super.initState();

    // If you're willing to create logs in debug
    crashOps.isEnabledInDebugMode = true;
    // If you wish to upload logs CrashOps servers
    crashOps.setApplicationKey(
        iosKey: "your-ios-application-key-from-crashops",
        androidKey: "your-android-application-key-from-crashops");
    // If you wish to add more details in each log
    crashOps.setMetadata({"yo": "that's my awesome app!"});
  }

  @override
  Widget build(BuildContext context) {
    // Platform messages are asynchronous, so we initialize in an async method.
    if (_isCrashOpsEnabled == null) {
      crashOps.isEnabled.then((isOn) {
        _isCrashOpsEnabled = isOn;
        setState(() {});
      });

      return Container();
    }

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('CrashOps plugin example'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text('Running on: ${Platform.operatingSystem}\n'),
              RaisedButton(
                onPressed: () async {
                  _isCrashOpsEnabled = await crashOps.isEnabled;
                  bool didUpdate =
                      await crashOps.setEnabled(!_isCrashOpsEnabled);
//                  didUpdate = await crashOps.setMetadata({"uid": "someUid"});

                  print("did update enabled status: $didUpdate");

                  if (didUpdate) {
                    _isCrashOpsEnabled = await crashOps.isEnabled;
                    setState(() {});
                  }
                },
                child: Text(_btnEnableTitle),
              ),
              RaisedButton(
                onPressed: () async {
                  String nullString;
                  print(nullString.split("nonce").toString());
                },
                child: Text("Cause error! 🐞"),
              ),
              RaisedButton(
                onPressed: () async {
                  NativeBridge.crashThisApp().then((didSucceed) {
                    if (didSucceed) {
                      print("this line cannot be printed, ever!");
                    }
                  });
                },
                child: Text("Crash app! 😱"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class NativeBridge {
  static const platform =
      const MethodChannel('crashops-flutter-example/native_channel');

  static const String SUCCESS_RESULT = "1";
  static const String FAILURE_RESULT = "0";

  static Future<bool> crashThisApp() async {
    String result = await _invokeNativeMethod("crash_the_app");
    return result == SUCCESS_RESULT;
  }

  static Future<String> _invokeNativeMethod(String methodName,
      [dynamic arguments]) async {
    String result;
    try {
      if (arguments == null) {
        result = await platform.invokeMethod(methodName);
      } else {
        result = await platform.invokeMethod(methodName, arguments);
      }
      print("Native method '$methodName' returned result: $result");
    } on PlatformException catch (e) {
      String errorMessageString =
          "Failed to run native method, error: '${e.message}'.";
      print(errorMessageString);
    }

    return result;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  crashops_flutter: ^0.2.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:crashops_flutter/crashops_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
18
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]
57
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:crashops_flutter/crashops_flutter.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:crashops_flutter/crashops_flutter.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:crashops_flutter/crashops_flutter.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:crashops_flutter/crashops_flutter.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • crashops_flutter that is a package requiring null.

Health suggestions

Fix lib/crashops_flutter.dart. (-0.50 points)

Analysis of lib/crashops_flutter.dart reported 1 hint:

line 230 col 10: 'onError' is deprecated and shouldn't be used. Use runZonedGuarded instead.

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
stack_trace ^1.9.3 1.9.5
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
path 1.7.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test