44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/errors/failure.dart';
|
|
import '../../core/network/api_handler.dart';
|
|
import 'app_side_panel.dart';
|
|
import 'app_toast.dart';
|
|
|
|
void showAccessDeniedSnackBar(BuildContext context, {String? message}) {
|
|
showAppToast(
|
|
context,
|
|
message ?? 'Access denied',
|
|
type: AppToastType.error,
|
|
);
|
|
}
|
|
|
|
void showSidePanelApiError(BuildContext context, Object error) {
|
|
final message = error is Failure
|
|
? (error is ValidationFailure
|
|
? validationErrorMessage(error)
|
|
: error.message)
|
|
: 'Something went wrong. Please try again.';
|
|
showSidePanelSnackBar(context, message);
|
|
}
|
|
|
|
void showApiFailureSnackBar(BuildContext context, Failure failure) {
|
|
if (isForbiddenFailure(failure)) {
|
|
showAccessDeniedSnackBar(context, message: failure.message);
|
|
return;
|
|
}
|
|
|
|
if (isConflictFailure(failure)) {
|
|
showAppToast(context, failure.message, type: AppToastType.warning);
|
|
return;
|
|
}
|
|
|
|
showAppToast(
|
|
context,
|
|
failure is ValidationFailure
|
|
? validationErrorMessage(failure)
|
|
: failure.message,
|
|
type: AppToastType.error,
|
|
);
|
|
}
|