crashops 0.0.3
crashops: ^0.0.3 copied to clipboard

This Flutter plugin will bridge your Flutter app to CrashOps SDK. CrashOps helps you easily get crash and error reports. Super easy to use.

example/lib/main.dart

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

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

void main() {
  // Catching errors in Flutter actually depends on the Flutter developer.
  // We simply store it in our servers and will let you know.
  var onError = FlutterError.onError;
  CrashOps crashOps = CrashOps();
  FlutterError.onError = (FlutterErrorDetails details) {
    crashOps.onError(details);
    FlutterError.dumpErrorToConsole(details, forceReport: false);
    if (onError != null && FlutterError.dumpErrorToConsole != onError) {
      onError(details);
    }
  };

  // From: https://flutter.dev/docs/cookbook/maintenance/error-reporting
  runZoned(() {
    runApp(MyApp());
  }, onError: (error, stackTrace) {
    // This catches also Dart errors, not only Flutter errors.
    // More details here: https://github.com/flutter/flutter/issues/11206
    crashOps.onError(error, stackTrace);

    if (error is FlutterErrorDetails) {
      FlutterErrorDetails details = error;

      FlutterError.dumpErrorToConsole(details, forceReport: false);
      if (onError != null && FlutterError.dumpErrorToConsole != onError) {
        onError(details);
      }
    }
  });
}

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

class _MyAppState extends State<MyApp> {
  final CrashOps crashOps = CrashOps();
  bool _isCrashOpsEnabled;

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

    crashOps.isEnabledInDebugMode = true;

    try {
      // Platform messages may fail, so we use a try/catch PlatformException.
      crashOps.setClientId(
          "the-client-id-you-received-from-crashops-customer-support");
      crashOps.setMetadata({"yo": "that's my awesome app!"});
    } on PlatformException {
      print("Error!");
    }
  }

  @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 host app'),
        ),
        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.setClientId("perry");
//                  didUpdate = await crashOps.setMetadata({"yo": "perry"});

                  print("didUpdate: $didUpdate");

                  if (didUpdate) {
                    _isCrashOpsEnabled = await crashOps.isEnabled;
                    setState(() {});
                  }
                },
                child: Text(_isCrashOpsEnabled ? "enabled" : "disabled"),
              ),
              RaisedButton(
                onPressed: () async {
                  String nullString;
                  print(nullString.split("nonce").toString());
                },
                child: Text("cause problem! 😱"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
90
pub points
7%
popularity

This Flutter plugin will bridge your Flutter app to CrashOps SDK. CrashOps helps you easily get crash and error reports. Super easy to use.

Homepage

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter, stack_trace

More

Packages that depend on crashops