From e3b099785bbe6ec957de7f28620b94792511f7f9 Mon Sep 17 00:00:00 2001 From: Andrea Bizzotto Date: Thu, 16 Nov 2023 11:44:52 +0000 Subject: [PATCH] Revert "Install multiple_result and use Result in the FakeAuthRepository" This reverts commit 17ef8476779e481a9ff15d533af3d3ddc31ebf64. --- .../data/fake_auth_repository.dart | 17 +++++++---------- .../email_password_sign_in_controller.dart | 11 ++--------- ecommerce_app/pubspec.lock | 8 -------- ecommerce_app/pubspec.yaml | 1 - 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/ecommerce_app/lib/src/features/authentication/data/fake_auth_repository.dart b/ecommerce_app/lib/src/features/authentication/data/fake_auth_repository.dart index cdf23a1e..63543e16 100644 --- a/ecommerce_app/lib/src/features/authentication/data/fake_auth_repository.dart +++ b/ecommerce_app/lib/src/features/authentication/data/fake_auth_repository.dart @@ -4,7 +4,6 @@ import 'package:ecommerce_app/src/features/authentication/domain/fake_app_user.d import 'package:ecommerce_app/src/utils/delay.dart'; import 'package:ecommerce_app/src/utils/in_memory_store.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:multiple_result/multiple_result.dart'; class FakeAuthRepository { FakeAuthRepository({this.addDelay = true}); @@ -17,40 +16,38 @@ class FakeAuthRepository { // List to keep track of all user accounts final List _users = []; - Future> signInWithEmailAndPassword( - String email, String password) async { + Future signInWithEmailAndPassword(String email, String password) async { await delay(addDelay); // check the given credentials agains each registered user for (final u in _users) { // matching email and password if (u.email == email && u.password == password) { _authState.value = u; - return const Success(null); + return; } // same email, wrong password if (u.email == email && u.password != password) { - return Error(WrongPasswordException()); + throw WrongPasswordException(); } } - return Error(UserNotFoundException()); + throw UserNotFoundException(); } - Future> createUserWithEmailAndPassword( + Future createUserWithEmailAndPassword( String email, String password) async { await delay(addDelay); // check if the email is already in use for (final u in _users) { if (u.email == email) { - return Error(EmailAlreadyInUseException()); + throw EmailAlreadyInUseException(); } } // minimum password length requirement if (password.length < 8) { - return Error(WeakPasswordException()); + throw WeakPasswordException(); } // create new user _createNewUser(email, password); - return const Success(null); } Future signOut() async { diff --git a/ecommerce_app/lib/src/features/authentication/presentation/sign_in/email_password_sign_in_controller.dart b/ecommerce_app/lib/src/features/authentication/presentation/sign_in/email_password_sign_in_controller.dart index 1ef2f9da..d04ef7c5 100644 --- a/ecommerce_app/lib/src/features/authentication/presentation/sign_in/email_password_sign_in_controller.dart +++ b/ecommerce_app/lib/src/features/authentication/presentation/sign_in/email_password_sign_in_controller.dart @@ -1,8 +1,6 @@ -import 'package:ecommerce_app/src/exceptions/app_exception.dart'; import 'package:ecommerce_app/src/features/authentication/data/fake_auth_repository.dart'; import 'package:ecommerce_app/src/features/authentication/presentation/sign_in/email_password_sign_in_state.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:multiple_result/multiple_result.dart'; class EmailPasswordSignInController extends StateNotifier { @@ -14,17 +12,12 @@ class EmailPasswordSignInController Future submit(String email, String password) async { state = state.copyWith(value: const AsyncValue.loading()); - final result = await _authenticate(email, password); - final value = result.when( - (success) => AsyncData(success), - (error) => AsyncError(error, StackTrace.current), - ) as AsyncValue; + final value = await AsyncValue.guard(() => _authenticate(email, password)); state = state.copyWith(value: value); return value.hasError == false; } - Future> _authenticate( - String email, String password) { + Future _authenticate(String email, String password) { switch (state.formType) { case EmailPasswordSignInFormType.signIn: return authRepository.signInWithEmailAndPassword(email, password); diff --git a/ecommerce_app/pubspec.lock b/ecommerce_app/pubspec.lock index 52466717..0ce65147 100644 --- a/ecommerce_app/pubspec.lock +++ b/ecommerce_app/pubspec.lock @@ -279,14 +279,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" - multiple_result: - dependency: "direct main" - description: - name: multiple_result - sha256: "9aba99bd75f28ac6519980580636348c0327e225d950a239fa59d2d983af4ce4" - url: "https://pub.dev" - source: hosted - version: "5.0.0" path: dependency: transitive description: diff --git a/ecommerce_app/pubspec.yaml b/ecommerce_app/pubspec.yaml index f6957643..8f00de40 100644 --- a/ecommerce_app/pubspec.yaml +++ b/ecommerce_app/pubspec.yaml @@ -22,7 +22,6 @@ dependencies: sembast: 3.5.0+1 sembast_web: 2.2.0 path_provider: 2.1.1 - multiple_result: 5.0.0 dev_dependencies: flutter_test: