mirror of
https://github.com/flutter/samples.git
synced 2026-06-02 12:29:50 +00:00
Fix crashlytics in game_template (#1998)
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
// Uncomment the following lines when enabling Firebase Crashlytics
|
||||
// import 'dart:io';
|
||||
// import 'package:firebase_core/firebase_core.dart';
|
||||
// import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
// import 'package:flutter/foundation.dart';
|
||||
// import 'firebase_options.dart';
|
||||
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'dart:developer' as dev;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -17,7 +20,6 @@ import 'package:provider/provider.dart';
|
||||
import 'src/ads/ads_controller.dart';
|
||||
import 'src/app_lifecycle/app_lifecycle.dart';
|
||||
import 'src/audio/audio_controller.dart';
|
||||
import 'src/crashlytics/crashlytics.dart';
|
||||
import 'src/games_services/games_services.dart';
|
||||
import 'src/games_services/score.dart';
|
||||
import 'src/in_app_purchase/in_app_purchase.dart';
|
||||
@@ -38,33 +40,45 @@ import 'src/style/snack_bar.dart';
|
||||
import 'src/win_game/win_game_screen.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
// To enable Firebase Crashlytics, uncomment the following lines and
|
||||
// the import statements at the top of this file.
|
||||
// Subscribe to log messages.
|
||||
Logger.root.onRecord.listen((record) {
|
||||
dev.log(
|
||||
record.message,
|
||||
time: record.time,
|
||||
level: record.level.value,
|
||||
name: record.loggerName,
|
||||
zone: record.zone,
|
||||
error: record.error,
|
||||
stackTrace: record.stackTrace,
|
||||
);
|
||||
});
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// TODO: To enable Firebase Crashlytics, uncomment the following line.
|
||||
// See the 'Crashlytics' section of the main README.md file for details.
|
||||
|
||||
FirebaseCrashlytics? crashlytics;
|
||||
// if (!kIsWeb && (Platform.isIOS || Platform.isAndroid)) {
|
||||
// try {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
// await Firebase.initializeApp(
|
||||
// options: DefaultFirebaseOptions.currentPlatform,
|
||||
// );
|
||||
// crashlytics = FirebaseCrashlytics.instance;
|
||||
//
|
||||
// FlutterError.onError = (errorDetails) {
|
||||
// FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
|
||||
// };
|
||||
//
|
||||
// // Pass all uncaught asynchronous errors
|
||||
// // that aren't handled by the Flutter framework to Crashlytics.
|
||||
// PlatformDispatcher.instance.onError = (error, stack) {
|
||||
// FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
|
||||
// return true;
|
||||
// };
|
||||
// } catch (e) {
|
||||
// debugPrint("Firebase couldn't be initialized: $e");
|
||||
// }
|
||||
// }
|
||||
|
||||
await guardWithCrashlytics(
|
||||
guardedMain,
|
||||
crashlytics: crashlytics,
|
||||
);
|
||||
}
|
||||
|
||||
/// Without logging and crash reporting, this would be `void main()`.
|
||||
void guardedMain() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
_log.info('Going full screen');
|
||||
SystemChrome.setEnabledSystemUIMode(
|
||||
SystemUiMode.edgeToEdge,
|
||||
|
||||
Reference in New Issue
Block a user