Приложение на флаторе, настройки

This commit is contained in:
Халимов Рустам
2026-05-13 17:21:37 +03:00
parent 89e325556c
commit e8161d23d4
119 changed files with 18469 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'errors.freezed.dart';
@freezed
class AppError with _$AppError {
const factory AppError.unknown({String? message}) = UnknownError;
const factory AppError.network({String? message}) = NetworkError;
const factory AppError.unauthorized({String? message}) = UnauthorizedError;
const factory AppError.forbidden({String? message}) = ForbiddenError;
const factory AppError.notFound({String? message}) = NotFoundError;
const factory AppError.server({int? statusCode, String? message}) = ServerError;
const factory AppError.database({String? message}) = DatabaseError;
const factory AppError.validation({Map<String, String>? fieldErrors}) = ValidationError;
}
File diff suppressed because it is too large Load Diff
+30
View File
@@ -0,0 +1,30 @@
import 'errors.dart';
/// A generic class for handling success/failure results
class Result<T> {
final T? data;
final AppError? error;
const Result.success(this.data) : error = null;
const Result.failure(this.error) : data = null;
bool get isSuccess => error == null;
bool get isFailure => error != null;
R when<R>({
required R Function(T data) onSuccess,
required R Function(AppError error) onFailure,
}) {
if (isSuccess) {
return onSuccess(data as T);
}
return onFailure(error!);
}
T getOrThrow() {
if (isFailure) {
throw error!;
}
return data as T;
}
}