Created
June 26, 2022 17:57
-
-
Save pawelsa/b2a500c7aba520ce761004ee1f61eec4 to your computer and use it in GitHub Desktop.
Results that can be returned from repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@freezed | |
class ErrorCause with _$ErrorCause { | |
const factory ErrorCause.noInternet() = NoInternetError; | |
const factory ErrorCause.databaseSave() = DatabaseSaveError; | |
const factory ErrorCause.unknown() = UnknownError; | |
} | |
@freezed | |
class Result with _$Result { | |
const factory Result.success() = SuccessfulResult; | |
const factory Result.error(ErrorCause error) = ErrorResult; | |
} | |
@freezed | |
class DataResult<T> with _$DataResult<T> { | |
const factory DataResult.success(T data) = SuccessfulDataResult<T>; | |
const factory DataResult.error(T data, ErrorCause error) = ErrorDataResult<T>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment