-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Restart App, Firebase Crashlytics
- Loading branch information
1 parent
c3cf95f
commit ebd6269
Showing
5 changed files
with
118 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:restart_app/restart_app.dart'; | ||
|
||
class ErrorScreen extends StatelessWidget { | ||
final String error; | ||
|
||
const ErrorScreen({super.key, required this.error}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const Icon(Icons.error_outline, color: Colors.red, size: 60), | ||
const SizedBox(height: 16), | ||
const Text( | ||
'Oops! Something went wrong.', | ||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 16), | ||
const Text( | ||
'We\'re sorry for the inconvenience. Our team has been notified and is working on fixing the issue.', | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 16), | ||
if (kDebugMode) | ||
Text( | ||
'Error details: $error', | ||
style: const TextStyle(fontSize: 12), | ||
textAlign: TextAlign.center, | ||
), | ||
const SizedBox(height: 32), | ||
ElevatedButton( | ||
child: const Text('Restart App'), | ||
onPressed: () { | ||
Restart.restartApp( | ||
notificationTitle: 'Restarting App', | ||
notificationBody: 'Please tap here to open the app again.', | ||
); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:get_storage/get_storage.dart'; | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:firebase_crashlytics/firebase_crashlytics.dart'; | ||
|
||
import 'core/app/controllers/core_controller.dart'; | ||
import 'core/app/views/root.dart'; | ||
import 'core/utils/ui_helper.dart'; | ||
import 'package:worker_manager/worker_manager.dart' as w; | ||
import 'error_screen.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
await GetStorage.init(); | ||
AppUiUtil.autoRotateOff(); | ||
final core = Get.put(CoreController()); | ||
await w.workerManager.init(); | ||
runApp(TuringTechApp(core: core)); | ||
runZonedGuarded(() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// Initialize Firebase | ||
await Firebase.initializeApp(); | ||
|
||
// Pass all uncaught errors to Crashlytics | ||
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; | ||
|
||
await GetStorage.init(); | ||
AppUiUtil.autoRotateOff(); | ||
final core = Get.put(CoreController()); | ||
await w.workerManager.init(); | ||
|
||
runApp(TuringTechApp(core: core)); | ||
}, (Object error, StackTrace stack) { | ||
FirebaseCrashlytics.instance.recordError(error, stack); | ||
debugPrint('Caught Dart error:'); | ||
debugPrint(error.toString()); | ||
debugPrint(stack.toString()); | ||
|
||
// Show error screen | ||
runApp(MaterialApp(home: ErrorScreen(error: error.toString()))); | ||
}); | ||
} |
This file contains 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
This file contains 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