Skip to content

Commit

Permalink
Firebase Crashlytics
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulUrtecho committed Jun 26, 2022
1 parent 116c53e commit adb1262
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.vscode

.env*
secret_config.json
pubspec\.lock
Expand Down
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
22 changes: 7 additions & 15 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413",
"mobilesdk_app_id": "1:366914936426:android:978896cb9d8996661a3413",
"android_client_info": {
"package_name": "com.joinseeds.seedswallet"
"package_name": "com.joinseeds.parq"
}
},
"oauth_client": [
{
"client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.joinseeds.seedswallet",
"certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270"
}
},
{
"client_id": "366914936426-92ud91kd7hqj98to79aospg00m3f3to7.apps.googleusercontent.com",
"client_type": 3
Expand Down Expand Up @@ -53,18 +45,18 @@
},
{
"client_info": {
"mobilesdk_app_id": "1:366914936426:android:389b18d13a862a531a3413",
"mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413",
"android_client_info": {
"package_name": "com.joinseeds.wallet"
"package_name": "com.joinseeds.seedswallet"
}
},
"oauth_client": [
{
"client_id": "366914936426-k4i8n24qb9eu1ug0cqs0rcfvc3pq1fh3.apps.googleusercontent.com",
"client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.joinseeds.wallet",
"certificate_hash": "1d4a3d87c78e5d83f8b7c7fb5240f10fe072132f"
"package_name": "com.joinseeds.seedswallet",
"certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ buildscript {

dependencies {
classpath 'com.google.gms:google-services:4.3.3'

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
7 changes: 7 additions & 0 deletions ios/firebase_app_id_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_generated_by": "FlutterFire CLI",
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
"GOOGLE_APP_ID": "1:366914936426:ios:75e7ba91678551811a3413",
"FIREBASE_PROJECT_ID": "seeds-77371",
"GCM_SENDER_ID": "366914936426"
}
27 changes: 18 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:isolate';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -15,7 +17,20 @@ import 'package:seeds/domain-shared/bloc_observer.dart';
import 'package:seeds/seeds_app.dart';

Future<void> main() async {
// Zone to handle asynchronous errors (Dart).
// To catch errors that happen outside of the Flutter context
// add an error listener on the current Isolate:
Isolate.current.setErrorsFatal(false);
Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await FirebaseCrashlytics.instance.recordError(
errorAndStacktrace.first,
errorAndStacktrace.last,
fatal: true,
);
}).sendPort);

// If we're using zones, instrumenting the zone’s error handler will catch errors
// that aren't caught by the Flutter framework (i.e. in a button’s onPressed handler)
// for details: https://docs.flutter.dev/testing/errors
await runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -29,19 +44,13 @@ Future<void> main() async {
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

// Called whenever the Flutter framework catches an error.
FlutterError.onError = (details) async {
FlutterError.presentError(details);
// TODO(Raul): use FirebaseCrashlytics or whatever
//await FirebaseCrashlytics.instance.recordFlutterError(details);
};
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;

if (kDebugMode) {
/// Bloc logs only in debug (for better performance in release)
BlocOverrides.runZoned(() => runApp(const SeedsApp()), blocObserver: DebugBlocObserver());
} else {
runApp(const SeedsApp());
}
}, (error, stackTrace) async {
//await FirebaseCrashlytics.instance.recordError(error, stack);
});
}, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack, fatal: true));
}
3 changes: 3 additions & 0 deletions lib/screens/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:seeds/blocs/deeplink/viewmodels/deeplink_bloc.dart';
import 'package:seeds/blocs/rates/viewmodels/rates_bloc.dart';
import 'package:seeds/components/full_page_loading_indicator.dart';
import 'package:seeds/components/notification_badge.dart';
import 'package:seeds/datasource/local/settings_storage.dart';
import 'package:seeds/design/app_colors.dart';
import 'package:seeds/design/app_theme.dart';
import 'package:seeds/domain-shared/event_bus/event_bus.dart';
Expand Down Expand Up @@ -61,6 +63,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
FirebaseCrashlytics.instance.setCustomKey('user', settingsStorage.accountName);
_appBloc = AppBloc(BlocProvider.of<DeeplinkBloc>(context))..add(const OnAppMounted());
_connectionNotifier = ConnectionNotifier()..discoverEndpoints();
BlocProvider.of<RatesBloc>(context).add(const OnFetchRates());
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies:
geolocator: ^8.2.0
geocoding: ^2.0.2
permission_handler: ^9.2.0
firebase_crashlytics: ^2.8.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit adb1262

Please sign in to comment.