Created
January 7, 2021 07:25
-
-
Save piumimaheshika/4991f8d7078e6d1230084f593bad1fba to your computer and use it in GitHub Desktop.
crashlytics flutter
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:firebase_crashlytics/firebase_crashlytics.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:firebase_core/firebase_core.dart'; | |
| class Wrapper extends StatefulWidget { | |
| // This widget is the root of your application. | |
| @override | |
| _WrapperState createState() => _WrapperState(); | |
| } | |
| class _WrapperState extends State<Wrapper> { | |
| Future<void> _initializeFuture; | |
| //init firebase crashlytics | |
| Future<void> _initializeFlutterFire() async { | |
| await Firebase.initializeApp(); | |
| //Force enable crashlytics collection enabled for debugging. | |
| await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); | |
| // Pass all uncaught errors to Crashlytics. | |
| Function originalOnError = FlutterError.onError; | |
| FlutterError.onError = (FlutterErrorDetails errorDetails) async { | |
| await FirebaseCrashlytics.instance.recordFlutterError(errorDetails); | |
| // Forward to original handler. | |
| originalOnError(errorDetails); | |
| }; | |
| } | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _initializeFuture = _initializeFlutterFire(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| visualDensity: VisualDensity.adaptivePlatformDensity, | |
| ), | |
| home: Scaffold( | |
| body: FutureBuilder( | |
| future: _initializeFuture, | |
| builder: (context, snapshot) { | |
| switch (snapshot.connectionState) { | |
| case ConnectionState.done: | |
| return DemoApp( | |
| .... | |
| .... | |
| .... | |
| ); | |
| break; | |
| default: | |
| return Center( | |
| child: Text('Loading...'), | |
| ); | |
| } | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment