Skip to content

Instantly share code, notes, and snippets.

@piumimaheshika
Created January 7, 2021 07:25
Show Gist options
  • Select an option

  • Save piumimaheshika/4991f8d7078e6d1230084f593bad1fba to your computer and use it in GitHub Desktop.

Select an option

Save piumimaheshika/4991f8d7078e6d1230084f593bad1fba to your computer and use it in GitHub Desktop.
crashlytics flutter
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