Disable crashlytics and analytics by default

This commit is contained in:
mehul425
2023-07-20 10:57:08 +05:30
parent 87940012eb
commit c54d1b88a9
3 changed files with 66 additions and 16 deletions

View File

@ -50,6 +50,40 @@ Overall all this puzzle tries to engage you in a different way to improve your m
**2) Picture Puzzle** : Each shape represents a number. You need find number related to each shape and solve the last equation.<br /> **2) Picture Puzzle** : Each shape represents a number. You need find number related to each shape and solve the last equation.<br />
**3) Number Pyramid** : In a number pyramid, the numbers on the lower layers determine the numbers above them. Sum of two consecutive cell would be placed on top cell.<br /> **3) Number Pyramid** : In a number pyramid, the numbers on the lower layers determine the numbers above them. Sum of two consecutive cell would be placed on top cell.<br />
## Crashlytics and Analytics
To enable Firebase Crashlytics and Analytics, do the following:
1. Create a new project in
[console.firebase.google.com](https://console.firebase.google.com/).
Call the Firebase project whatever you like; just **remember the name**.
You don't need to enable Analytics in the project if you don't want to.
2. [Install `firebase-tools`](https://firebase.google.com/docs/cli?authuser=0#setup_update_cli)
on your machine.
3. [Install `flutterfire` CLI](https://firebase.flutter.dev/docs/cli#installation)
on your machine.
4. In the root of this project (the directory containing `pubspec.yaml`),
run the following:
- `flutterfire configure`
- This command asks you for the name of the Firebase project
that you created earlier, and the list of target platforms you support.
As of April 2022, only `android` and `ios` are fully
supported by Crashlytics.
- The command rewrites `lib/firebase_options.dart` with
the correct code.
5. Go to `lib/main.dart` and uncomment the lines that relate to Crashlytics and Analytics.
You should now be able to see crashes, errors, and
severe log messages in
[console.firebase.google.com](https://console.firebase.google.com/).
To test, add a button to your project, and throw whatever
exception you like when the player presses it.
```dart
TextButton(
onPressed: () => throw StateError('whoa!'),
child: Text('Test Crashlytics'),
)
```
## Built With ## Built With
This application built [Flutter](https://flutter.dev/). Flutter is cross-platform open source mobile framework built by Google. Flutter use Dart as a primary language which is highly scalable and easy codebase. This application built [Flutter](https://flutter.dev/). Flutter is cross-platform open source mobile framework built by Google. Flutter use Dart as a primary language which is highly scalable and easy codebase.

View File

@ -1,17 +1,19 @@
import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_animate/flutter_animate.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:mathgame/firebase_options.dart';
import 'package:mathgame/src/ui/app/app.dart'; import 'package:mathgame/src/ui/app/app.dart';
import 'package:mathgame/src/ui/app/theme_provider.dart'; import 'package:mathgame/src/ui/app/theme_provider.dart';
import 'package:mathgame/src/ui/dashboard/dashboard_provider.dart'; import 'package:mathgame/src/ui/dashboard/dashboard_provider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
// Uncomment the following lines when enabling Firebase Crashlytics
// import 'package:firebase_core/firebase_core.dart';
// import 'package:mathgame/firebase_options.dart';
Future<void> main() async { Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -19,23 +21,36 @@ Future<void> main() async {
Animate.restartOnHotReload = true; Animate.restartOnHotReload = true;
} }
await Firebase.initializeApp( FirebaseAnalytics? firebaseAnalytics;
options: DefaultFirebaseOptions.currentPlatform, FirebaseCrashlytics? crashlytics;
);
FirebaseAnalytics firebaseAnalytics = FirebaseAnalytics.instance; // To enable Firebase Crashlytics and Analytics, uncomment the following lines and
// the import statements at the top of this file.
// See the 'Crashlytics and Analytics' section of the main README.md file for details.
// try {
// await Firebase.initializeApp(
// options: DefaultFirebaseOptions.currentPlatform,
// );
// firebaseAnalytics = FirebaseAnalytics.instance;
// crashlytics = FirebaseCrashlytics.instance;
// } catch (e) {
// debugPrint("Firebase couldn't be initialized: $e");
// }
if (kDebugMode) { if (kDebugMode) {
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false); await crashlytics?.setCrashlyticsCollectionEnabled(false);
await firebaseAnalytics.setAnalyticsCollectionEnabled(false); await firebaseAnalytics?.setAnalyticsCollectionEnabled(false);
} }
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; if (crashlytics != null) {
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
PlatformDispatcher.instance.onError = (error, stack) { PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true; return true;
}; };
}
final sharedPreferences = await SharedPreferences.getInstance(); final sharedPreferences = await SharedPreferences.getInstance();

View File

@ -2,14 +2,14 @@ import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:mathgame/src/core/app_constant.dart'; import 'package:mathgame/src/core/app_constant.dart';
import 'package:mathgame/src/core/app_theme.dart';
import 'package:mathgame/src/core/app_routes.dart'; import 'package:mathgame/src/core/app_routes.dart';
import 'package:mathgame/src/core/app_theme.dart';
import 'package:mathgame/src/ui/app/theme_provider.dart'; import 'package:mathgame/src/ui/app/theme_provider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
final String fontFamily = "Montserrat"; final String fontFamily = "Montserrat";
final FirebaseAnalytics firebaseAnalytics; final FirebaseAnalytics? firebaseAnalytics;
const MyApp({ const MyApp({
required this.firebaseAnalytics, required this.firebaseAnalytics,
@ -35,7 +35,8 @@ class MyApp extends StatelessWidget {
routes: appRoutes, routes: appRoutes,
// home: DashboardView(), // home: DashboardView(),
navigatorObservers: [ navigatorObservers: [
FirebaseAnalyticsObserver(analytics: firebaseAnalytics) if (firebaseAnalytics != null)
FirebaseAnalyticsObserver(analytics: firebaseAnalytics!)
], ],
); );
}); });