Skip to content

Commit

Permalink
Feature: Implemented the Custom Error Screen (#183)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
superiorsd10 authored Dec 10, 2023
1 parent 03bc8a1 commit 224d5e2
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/images/warning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions lib/app/utils/custom_error_screen.dart
Original file line number Diff line number Diff line change
@@ -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<CustomErrorScreen> createState() => _CustomErrorScreenState();
}

class _CustomErrorScreenState extends State<CustomErrorScreen> {
ThemeController themeController = Get.put<ThemeController>(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,
),
),
),
],
),
),
),
),
);
}
}
22 changes: 19 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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!;
},
);
}
}

0 comments on commit 224d5e2

Please sign in to comment.