Skip to content

Commit

Permalink
Added Restart App, Firebase Crashlytics
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmominsakib committed Oct 12, 2024
1 parent c3cf95f commit ebd6269
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 14 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ android {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
shrinkResources false
minifyEnabled false
multiDexEnabled true
Expand Down
54 changes: 54 additions & 0 deletions lib/error_screen.dart
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.',
);
},
),
],
),
),
),
);
}
}
35 changes: 29 additions & 6 deletions lib/main.dart
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())));
});
}
38 changes: 31 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: _flutterfire_internals
sha256: f5628cd9c92ed11083f425fd1f8f1bc60ecdda458c81d73b143aeda036c35fe7
sha256: "37a42d06068e2fe3deddb2da079a8c4d105f241225ba27b7122b37e9865fd8f7"
url: "https://pub.dev"
source: hosted
version: "1.3.16"
version: "1.3.35"
animations:
dependency: "direct main"
description:
Expand Down Expand Up @@ -309,10 +309,10 @@ packages:
dependency: "direct main"
description:
name: firebase_core
sha256: "96607c0e829a581c2a483c658f04e8b159964c3bae2730f73297070bc85d40bb"
sha256: "26de145bb9688a90962faec6f838247377b0b0d32cc0abecd9a4e43525fc856c"
url: "https://pub.dev"
source: hosted
version: "2.24.2"
version: "2.32.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand All @@ -325,10 +325,26 @@ packages:
dependency: transitive
description:
name: firebase_core_web
sha256: d585bdf3c656c3f7821ba1bd44da5f13365d22fcecaf5eb75c4295246aaa83c0
sha256: f4ee170441ca141c5f9ee5ad8737daba3ee9c8e7efb6902aee90b4fbd178ce25
url: "https://pub.dev"
source: hosted
version: "2.10.0"
version: "2.18.0"
firebase_crashlytics:
dependency: "direct main"
description:
name: firebase_crashlytics
sha256: "9897c01efaa950d2f6da8317d12452749a74dc45f33b46390a14cfe28067f271"
url: "https://pub.dev"
source: hosted
version: "3.5.7"
firebase_crashlytics_platform_interface:
dependency: transitive
description:
name: firebase_crashlytics_platform_interface
sha256: "16a71e08fbf6e00382816e1b13397898c29a54fa0ad969c2c2a3b82a704877f0"
url: "https://pub.dev"
source: hosted
version: "3.6.35"
firebase_messaging:
dependency: "direct main"
description:
Expand Down Expand Up @@ -856,6 +872,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.0"
restart_app:
dependency: "direct main"
description:
name: restart_app
sha256: "00d5ec3e9de871cedbe552fc41e615b042b5ec654385e090e0983f6d02f655ed"
url: "https://pub.dev"
source: hosted
version: "1.3.2"
retry:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1150,5 +1174,5 @@ packages:
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.5.0 <4.0.0"
dart: ">=3.5.1 <4.0.0"
flutter: ">=3.22.0"
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dependencies:
worker_manager: ^7.0.3
persistent_bottom_nav_bar: ^6.2.1
auto_size_text: ^3.0.0
firebase_crashlytics: ^3.5.7
restart_app: ^1.3.2

dev_dependencies:
flutter_test:
Expand All @@ -56,6 +58,7 @@ dev_dependencies:
flutter_lints: ^4.0.0
change_app_package_name: ^1.0.0


flutter:
uses-material-design: true

Expand Down

0 comments on commit ebd6269

Please sign in to comment.