From 224d5e22a3d00053df77a55dd6985e04eb31fe80 Mon Sep 17 00:00:00 2001 From: Sachin Dapkara <92971894+superiorsd10@users.noreply.github.com> Date: Sun, 10 Dec 2023 15:59:26 +0530 Subject: [PATCH] Feature: Implemented the Custom Error Screen (#183) * adding the error svg asset * implementing the custom error screen * adding the builder function to material app * adding the title showing that error has occurred * changing the fromLTRB to all --- assets/images/warning.svg | 1 + lib/app/utils/custom_error_screen.dart | 99 ++++++++++++++++++++++++++ lib/main.dart | 22 +++++- 3 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 assets/images/warning.svg create mode 100644 lib/app/utils/custom_error_screen.dart diff --git a/assets/images/warning.svg b/assets/images/warning.svg new file mode 100644 index 00000000..eea06853 --- /dev/null +++ b/assets/images/warning.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lib/app/utils/custom_error_screen.dart b/lib/app/utils/custom_error_screen.dart new file mode 100644 index 00000000..73491590 --- /dev/null +++ b/lib/app/utils/custom_error_screen.dart @@ -0,0 +1,99 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:get/get.dart'; +import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; +import 'package:ultimate_alarm_clock/app/utils/constants.dart'; + +class CustomErrorScreen extends StatefulWidget { + const CustomErrorScreen({ + super.key, + required this.errorDetails, + }); + + final FlutterErrorDetails? errorDetails; + + @override + State createState() => _CustomErrorScreenState(); +} + +class _CustomErrorScreenState extends State { + ThemeController themeController = Get.put(ThemeController()); + + @override + Widget build(BuildContext context) { + var height = Get.height; + var width = Get.width; + return Scaffold( + backgroundColor: themeController.isLightMode.value + ? kLightPrimaryBackgroundColor + : kprimaryBackgroundColor, + body: SafeArea( + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Error Occurred', + style: Theme.of(context).textTheme.titleLarge!.copyWith( + color: themeController.isLightMode.value + ? kLightPrimaryTextColor + : kprimaryTextColor, + ), + ), + SizedBox( + height: height * 0.18, + ), + SvgPicture.asset( + 'assets/images/warning.svg', + height: height * 0.3, + width: width * 0.8, + ), + const SizedBox( + height: 30, + ), + Text( + kDebugMode + ? widget.errorDetails!.summary.toString() + : 'Something went wrong! Don\'t worry we\'re' + 'working on it!', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: themeController.isLightMode.value + ? kLightPrimaryTextColor + : kprimaryTextColor, + ), + ), + const SizedBox( + height: 30, + ), + OutlinedButton( + onPressed: () { + Get.offNamedUntil( + '/home', + (route) => route.settings.name == '/splash-screen', + ); + }, + style: OutlinedButton.styleFrom( + side: const BorderSide( + color: kprimaryColor, + width: 1, + ), + ), + child: Text( + 'Navigate to Home', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: kprimaryColor, + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 0b5d4f51..1d24c994 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/custom_error_screen.dart'; import 'app/routes/app_pages.dart'; void main() async { @@ -19,13 +20,28 @@ void main() async { ); runApp( - GetMaterialApp( + const UltimateAlarmClockApp(), + ); +} + +class UltimateAlarmClockApp extends StatelessWidget { + const UltimateAlarmClockApp({super.key}); + + @override + Widget build(BuildContext context) { + return GetMaterialApp( theme: kLightThemeData, darkTheme: kThemeData, themeMode: ThemeMode.system, title: 'UltiClock', initialRoute: AppPages.INITIAL, getPages: AppPages.routes, - ), - ); + builder: (BuildContext context, Widget? error) { + ErrorWidget.builder = (FlutterErrorDetails? error) { + return CustomErrorScreen(errorDetails: error!); + }; + return error!; + }, + ); + } }