feat: add arch

This commit is contained in:
Yashar Panahi
2025-08-02 12:31:42 +03:30
parent 59c3091b2f
commit 64c4ebf0f8
12 changed files with 231 additions and 110 deletions
View File
View File
View File
View File
+21
View File
@@ -0,0 +1,21 @@
class AppException implements Exception {
final String message;
final String prefix;
AppException([this.message = 'An unknown error occurred.', this.prefix = '']);
@override
String toString() {
return '$prefix$message';
}
}
class FetchDataException extends AppException {
FetchDataException([String? message])
: super(message ?? 'Error During Communication: ', 'Network Error');
}
class AuthenticationException extends AppException {
AuthenticationException([String? message])
: super(message ?? 'Authentication Failed.', 'Auth Error');
}
+31
View File
@@ -0,0 +1,31 @@
sealed class Result<T> {
const Result();
/// Creates a successful [Result], completed with the specified [value].
const factory Result.ok(T value) = Ok._;
/// Creates an error [Result], completed with the specified [error].
const factory Result.error(Exception error) = Error._;
}
/// Subclass of Result for values
final class Ok<T> extends Result<T> {
const Ok._(this.value);
/// Returned value in result
final T value;
@override
String toString() => 'Result<$T>.ok($value)';
}
/// Subclass of Result for errors
final class Error<T> extends Result<T> {
const Error._(this.error);
/// Returned error in result
final Exception error;
@override
String toString() => 'Result<$T>.error($error)';
}