56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:birzha/models/settings/settingsModel.dart';
|
|
import 'package:birzha/screens/auth/login.dart';
|
|
import 'package:birzha/services/modals.dart';
|
|
|
|
abstract class AppExceptions implements Exception {
|
|
final String message;
|
|
AppExceptions({required this.message});
|
|
|
|
factory AppExceptions.recognizer(Map data) {
|
|
var message = data['error'];
|
|
if (message != null && message is Map) {
|
|
var translated = message['backendCode'.translation];
|
|
return MessageException(translated);
|
|
} else
|
|
return OtherException();
|
|
}
|
|
|
|
static void exceptionHandler(BuildContext context, dynamic exception) {
|
|
if (exception is OtherException) {
|
|
showSnackBar(context, content: exception.message.translation);
|
|
} else if (exception is CartProblemException)
|
|
showSnackBar(context,
|
|
content: exception.message, duration: Duration(seconds: 4));
|
|
else if (exception is UnAuthenticatedException)
|
|
Navigator.of(context, rootNavigator: true)
|
|
.push(MaterialPageRoute(builder: (_) => LoginScreen()));
|
|
else if (exception is MessageException) {
|
|
showSnackBar(context, content: exception.message);
|
|
} else {
|
|
showSnackBar(context, content: OtherException().message.translation);
|
|
}
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return message;
|
|
}
|
|
}
|
|
|
|
class OtherException extends AppExceptions {
|
|
OtherException() : super(message: 'otherException');
|
|
}
|
|
|
|
class MessageException extends AppExceptions {
|
|
MessageException(String message) : super(message: message);
|
|
}
|
|
|
|
class UnAuthenticatedException extends MessageException {
|
|
UnAuthenticatedException() : super('unauthenticated'.translation);
|
|
}
|
|
|
|
class CartProblemException extends MessageException {
|
|
CartProblemException() : super('cartProblem'.translation);
|
|
}
|