resultBasedHandling function
Implementation
void resultBasedHandling(AuthService authService) async {
final result = await authService.signInWithEmailAndPasswordResult(
email: 'user@example.com',
password: 'password',
);
// Pattern matching style
result.when(
success: (_) {
print('Login successful!');
navigateToHome();
},
failure: (error) {
print('Login failed: ${error.message}');
// Handle specific error types
switch (error.errorType) {
case AuthErrorType.invalidCredentials:
showError('Invalid email or password');
break;
case AuthErrorType.network:
showError('Network error');
break;
default:
showError(error.message);
}
},
);
// Or use conditional checks
if (result.isSuccess) {
print('Success!');
} else {
print('Error: ${result.error?.message}');
}
}