@@ -16,15 +16,15 @@ part 'custom_exception.freezed.dart';
1616sealed class CustomException with _$CustomException implements Exception {
1717 const CustomException ._();
1818
19- const factory CustomException .general () = CustomExceptionGeneral ;
20- const factory CustomException .withMessage ({String ? message}) = CustomExceptionWithMessage ;
21- const factory CustomException .unauthenticated () = CustomExceptionUnauthenticated ;
22- const factory CustomException .notConnectedToTheInternet () = CustomExceptionNotConnectedToTheInternet ;
23- const factory CustomException .decodingFailed () = CustomExceptionDecodingFailed ;
19+ const factory CustomException .general () = _General ;
20+ const factory CustomException .withMessage ({String ? message}) = _WithMessage ;
21+ const factory CustomException .unauthenticated () = _Unauthenticated ;
22+ const factory CustomException .notConnectedToTheInternet () = _NotConnectedToTheInternet ;
23+ const factory CustomException .decodingFailed () = _DecodingFailed ;
2424
2525 // Note: Mapped Firebase exception with error code `credential-already-in-use`.
26- const factory CustomException .signInCancelled () = CustomExceptionSignInCancelled ;
27- const factory CustomException .credentialAlreadyInUse ({required AuthCredential ? credential}) = CustomExceptionCredentialAlreadyInUse ;
26+ const factory CustomException .signInCancelled () = _SignInCancelled ;
27+ const factory CustomException .credentialAlreadyInUse ({required AuthCredential ? credential}) = _CredentialAlreadyInUse ;
2828
2929 factory CustomException .fromErrorObject ({required Object ? error}) {
3030 Flogger .e ('[CustomException] Received error $error , ' );
@@ -78,21 +78,17 @@ sealed class CustomException with _$CustomException implements Exception {
7878 }
7979 }
8080
81- String getMessage ({required BuildContext context}) {
82- return switch (this ) {
83- CustomExceptionWithMessage (message: final message) => message ?? context.locale.customExceptionGeneralMessage,
84- CustomExceptionUnauthenticated () => context.locale.customExceptionUnauthenticatedMessage,
85- CustomExceptionNotConnectedToTheInternet () => context.locale.customExceptionInternetConnectionMessage,
86- _ => context.locale.customExceptionGeneralMessage,
87- };
88- }
81+ String getMessage ({required BuildContext context}) => maybeWhen (
82+ withMessage: (message) => message ?? context.locale.customExceptionGeneralMessage,
83+ unauthenticated: () => context.locale.customExceptionUnauthenticatedMessage,
84+ notConnectedToTheInternet: () => context.locale.customExceptionInternetConnectionMessage,
85+ orElse: () => context.locale.customExceptionGeneralMessage,
86+ );
8987
90- String getDetails ({required BuildContext context}) {
91- return switch (this ) {
92- CustomExceptionNotConnectedToTheInternet () => context.locale.customExceptionInternetConnectionDetails,
93- _ => context.locale.customExceptionGeneralDetails,
94- };
95- }
88+ String getDetails ({required BuildContext context}) => maybeWhen (
89+ notConnectedToTheInternet: () => context.locale.customExceptionInternetConnectionDetails,
90+ orElse: () => context.locale.customExceptionGeneralDetails,
91+ );
9692
9793 Future <void > showErrorSnackbar ({
9894 required BuildContext context,
0 commit comments