Skip to content

Commit

Permalink
handle error widegt
Browse files Browse the repository at this point in the history
  • Loading branch information
mirmoktadir committed Feb 6, 2023
1 parent 9f19566 commit 921b997
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 89 deletions.
1 change: 1 addition & 0 deletions animations/apiError.json

Large diffs are not rendered by default.

75 changes: 0 additions & 75 deletions lib/app/components/custom_snackbar.dart

This file was deleted.

9 changes: 8 additions & 1 deletion lib/app/components/empty_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ class EmptyWidget extends StatelessWidget {
size: 24,
color: theme.primaryColor.withOpacity(.7),
)),
)
),
const SizedBox(height: 5),
Text(
"refresh!",
style: TextStyle(
color: theme.hintColor.withOpacity(.5),
),
),
],
),
);
Expand Down
10 changes: 6 additions & 4 deletions lib/app/service/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import '../components/custom_snackbar.dart';
import 'api_exceptions.dart';
import 'helper/dialog_helper.dart';

Expand All @@ -12,9 +11,8 @@ class BaseController {
hideLoading();
isError.value = true;
var errorText = DioExceptions.fromDioError(error).toString();
Timer(const Duration(milliseconds: 700), () {
CustomSnackBar.showCustomErrorToast(title: "Error", message: errorText);
});

showErrorDialog("Oops!", errorText);

if (kDebugMode) {
print(errorText);
Expand All @@ -29,4 +27,8 @@ class BaseController {
hideLoading() {
DialogHelper.hideLoading();
}

showErrorDialog(String title, String message) {
DialogHelper.showErrorDialog(title, message);
}
}
30 changes: 21 additions & 9 deletions lib/app/service/helper/dialog_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class DialogHelper {
static get context => null;

//show error dialog
static void showErrorDialog(
{String title = 'Error', String? description = 'Something went wrong'}) {
static void showErrorDialog(String title, String description) {
Get.dialog(
Dialog(
child: Padding(
Expand All @@ -19,13 +18,23 @@ class DialogHelper {
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
title ?? "",
style: Get.textTheme.headlineMedium,
),
SizedBox(height: 10.h),
Lottie.asset(
'animations/apiError.json',
height: 140.h,
repeat: true,
reverse: true,
fit: BoxFit.cover,
),
SizedBox(height: 10.h),
Text(
description ?? '',
description ?? "",
style: Get.textTheme.titleLarge,
),
SizedBox(height: 30.h),
ElevatedButton(
onPressed: () {
if (Get.isDialogOpen!) Get.back();
Expand Down Expand Up @@ -69,10 +78,13 @@ class DialogHelper {

//hide loading
static void hideLoading() {
Timer(const Duration(milliseconds: 700), () {
if (Get.isDialogOpen!) {
Get.back();
}
});
// Timer(const Duration(milliseconds: 700), () {
// if (Get.isDialogOpen!) {
// Get.back();
// }
// });
if (Get.isDialogOpen!) {
Get.back();
}
}
}

0 comments on commit 921b997

Please sign in to comment.