Created
September 7, 2019 14:19
-
-
Save Zfinix/c58814b4190ed8fb521b0ec650e43f82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:firebase_crashlytics/firebase_crashlytics.dart'; | |
| class CrashTest extends StatefulWidget { | |
| CrashTest({Key key}) : super(key: key); | |
| _CrashTestState createState() => _CrashTestState(); | |
| } | |
| class _CrashTestState extends State<CrashTest> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('Crash Test'), | |
| ), | |
| body: Center( | |
| child: Column( | |
| children: <Widget>[ | |
| FlatButton( | |
| child: const Text('Key'), | |
| onPressed: () { | |
| Crashlytics.instance.setString('foo', 'bar'); | |
| }), | |
| FlatButton( | |
| child: const Text('Log'), | |
| onPressed: () { | |
| Crashlytics.instance.log('baz'); | |
| }), | |
| FlatButton( | |
| child: const Text('Crash'), | |
| onPressed: () { | |
| // Use Crashlytics to throw an error. Use this for | |
| // confirmation that errors are being correctly reported. | |
| Crashlytics.instance.crash(); | |
| }), | |
| FlatButton( | |
| child: const Text('Throw Error'), | |
| onPressed: () { | |
| // Example of thrown error, it will be caught and sent to | |
| // Crashlytics. | |
| throw StateError('Uncaught error thrown by app.'); | |
| }), | |
| FlatButton( | |
| child: const Text('Async out of bounds'), | |
| onPressed: () { | |
| // Example of an exception that does not get caught | |
| // by `FlutterError.onError` but is caught by the `onError` handler of | |
| // `runZoned`. | |
| Future<void>.delayed(Duration(seconds: 2), () { | |
| final List<int> list = <int>[]; | |
| print(list[100]); | |
| }); | |
| }), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment