diff --git a/app/lib/app/data/repository/auth_repositoty_impl.dart b/app/lib/app/data/repository/auth_repositoty_impl.dart index 7b4ac921..468eb855 100644 --- a/app/lib/app/data/repository/auth_repositoty_impl.dart +++ b/app/lib/app/data/repository/auth_repositoty_impl.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; import 'package:my_quran/core/core.dart'; diff --git a/app/lib/app/data/source/auth_remote_data_source.dart b/app/lib/app/data/source/auth_remote_data_source.dart index e5a57563..cf24b589 100644 --- a/app/lib/app/data/source/auth_remote_data_source.dart +++ b/app/lib/app/data/source/auth_remote_data_source.dart @@ -1,5 +1,5 @@ +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; abstract class AuthRemoteDataSource { Future loginWithEmail(String email); diff --git a/app/lib/app/data/source/mock/auth_remote_data_source_mock.dart b/app/lib/app/data/source/mock/auth_remote_data_source_mock.dart index 7848cbe8..f265093d 100644 --- a/app/lib/app/data/source/mock/auth_remote_data_source_mock.dart +++ b/app/lib/app/data/source/mock/auth_remote_data_source_mock.dart @@ -1,8 +1,7 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; - @immutable final class AuthRemoteDataSourceMock implements AuthRemoteDataSource { const AuthRemoteDataSourceMock(); diff --git a/app/lib/app/data/source/remote/auth_remote_data_source_impl.dart b/app/lib/app/data/source/remote/auth_remote_data_source_impl.dart index 3d4615b7..086dcc25 100644 --- a/app/lib/app/data/source/remote/auth_remote_data_source_impl.dart +++ b/app/lib/app/data/source/remote/auth_remote_data_source_impl.dart @@ -1,4 +1,5 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:mq_storage/mq_storage.dart'; import 'package:my_quran/app/app.dart'; import 'package:my_quran/config/config.dart'; diff --git a/app/lib/app/domain/repository/auth_repository.dart b/app/lib/app/domain/repository/auth_repository.dart index 36e95964..db73673e 100644 --- a/app/lib/app/domain/repository/auth_repository.dart +++ b/app/lib/app/domain/repository/auth_repository.dart @@ -1,5 +1,5 @@ +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; abstract class AuthRepository { UserEntity? get init; diff --git a/app/lib/app/domain/usecase/apple_sign_in_use_case.dart b/app/lib/app/domain/usecase/apple_sign_in_use_case.dart index 8bad4d48..22adad62 100644 --- a/app/lib/app/domain/usecase/apple_sign_in_use_case.dart +++ b/app/lib/app/domain/usecase/apple_sign_in_use_case.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; @immutable final class AppleSignInUseCase { diff --git a/app/lib/app/domain/usecase/google_sign_in_use_case.dart b/app/lib/app/domain/usecase/google_sign_in_use_case.dart index 45d40ea8..d84b4920 100644 --- a/app/lib/app/domain/usecase/google_sign_in_use_case.dart +++ b/app/lib/app/domain/usecase/google_sign_in_use_case.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; @immutable final class GoogleSignInUseCase { diff --git a/app/lib/app/domain/usecase/patch_gender_user_case.dart b/app/lib/app/domain/usecase/patch_gender_user_case.dart index 2091ae88..d408e974 100644 --- a/app/lib/app/domain/usecase/patch_gender_user_case.dart +++ b/app/lib/app/domain/usecase/patch_gender_user_case.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; @immutable final class PatchGenderUseCase { diff --git a/app/lib/app/domain/usecase/patch_locale_code_use_case.dart b/app/lib/app/domain/usecase/patch_locale_code_use_case.dart index 4992b7b3..e9d3c067 100644 --- a/app/lib/app/domain/usecase/patch_locale_code_use_case.dart +++ b/app/lib/app/domain/usecase/patch_locale_code_use_case.dart @@ -1,6 +1,6 @@ import 'package:meta/meta.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/app/app.dart'; -import 'package:my_quran/core/core.dart'; @immutable final class PatchLocaleCodeUseCase { diff --git a/app/lib/core/client/mq_dio.dart b/app/lib/core/client/mq_dio.dart index 08c9addc..ec2cbee8 100644 --- a/app/lib/core/client/mq_dio.dart +++ b/app/lib/core/client/mq_dio.dart @@ -1,5 +1,6 @@ import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; +import 'package:mq_either/mq_either.dart'; import 'package:my_quran/core/core.dart'; part 'mq_dio_base_extension.dart'; diff --git a/app/lib/core/core.dart b/app/lib/core/core.dart index 72205982..697cbdb4 100644 --- a/app/lib/core/core.dart +++ b/app/lib/core/core.dart @@ -3,7 +3,6 @@ export 'client/network_client.dart'; export 'client/http_exception.dart'; export 'client/mq_dio.dart'; export 'crashlytics/mq_crashlytics.dart'; -export 'either/either.dart'; export 'exceptions/network_exception.dart'; export 'exceptions/server_exception.dart'; export 'exceptions/auth_exception.dart'; diff --git a/app/lib/core/either/either.dart b/app/lib/core/either/either.dart deleted file mode 100644 index e46f4281..00000000 --- a/app/lib/core/either/either.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'package:meta/meta.dart'; - -/// The Either class is an abstract class representing right and left values. -/// ```dart -/// void main() { -/// // Creating a Right instance representing the right value. -/// final rightValue = Right(42); -/// -/// // Creating a Left instance representing the left value. -/// final leftValue = Left('Error'); -/// -/// // Values can be processed using the fold method. -/// -/// // Calling fold on rightValue. -/// final rightResult = rightValue.fold( -/// (error) => 'Left: $error', // This function is executed if there is no right value. -/// (value) => 'Right: $value', // This function is executed if there is a right value. -/// ); -/// print(rightResult); // Output: "Right: 42" -/// -/// // Calling fold on leftValue. -/// final leftResult = leftValue.fold( -/// (error) => 'Left: $error', // This function is executed if there is a left value. -/// (value) => 'Right: $value', // This function is executed if there is no left value. -/// ); -/// print(leftResult); // Output: "Left: Error" -/// } -/// ``` -abstract class Either { - const Either(); - - /// The fold method allows performing operations based on right and left values. - /// B is a type parameter and it performs operations using the ifLeft and ifRight functions. - B fold(B Function(L l) ifLeft, B Function(R r) ifRight); -} - -/// The Right class is derived from the Either class and represents the right value. -/// ```dart -/// void main() { -/// // Creating a Right instance representing the right value. -/// final rightValue = Right(42); -/// -/// // Calling fold on rightValue. -/// final rightResult = rightValue.fold( -/// (error) => 'Left: $error', // This function is executed if there is no right value. -/// (value) => 'Right: $value', // This function is executed if there is a right value. -/// ); -/// print(rightResult); // Output: "Right: 42" -/// } -/// ``` -@immutable -final class Right extends Either { - const Right(this.r); - - /// A field is defined to hold the right value. - final R r; - - /// The fold method invokes the ifRight function using the right value and returns the result. - @override - B fold(B Function(L l) ifLeft, B Function(R r) ifRight) => ifRight(r); - - /// Equality check is defined for operator == and hashCode is computed for hashing. - @override - bool operator ==(Object other) => other is Right && other.r == r; - - @override - int get hashCode => r.hashCode; -} - -/// The Left class is derived from the Either class and represents the left value. -/// ```dart -/// void main() { -/// // Creating a Left instance representing the left value. -/// final leftValue = Left('Error'); -/// -/// // Calling fold on leftValue. -/// final leftResult = leftValue.fold( -/// (error) => 'Left: $error', // This function is executed if there is a left value. -/// (value) => 'Right: $value', // This function is executed if there is no left value. -/// ); -/// print(leftResult); // Output: "Left: -/// } -/// ``` -@immutable -final class Left extends Either { - const Left(this.l); - - /// A field is defined to hold the left value. - final L l; - - /// The fold method invokes the ifLeft function using the left value and returns the result. - @override - B fold(B Function(L l) ifLeft, B Function(R r) ifRight) => ifLeft(l); - - /// Equality check is defined for operator == and hashCode is computed for hashing. - @override - bool operator ==(Object other) => other is Left && other.l == l; - - @override - int get hashCode => l.hashCode; -} diff --git a/app/pubspec.lock b/app/pubspec.lock index e00f2683..345ab1a3 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -822,6 +822,13 @@ packages: relative: true source: path version: "1.0.0" + mq_either: + dependency: "direct main" + description: + path: "../packages/mq_either" + relative: true + source: path + version: "0.1.0+1" mq_storage: dependency: "direct main" description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 9766ff7c..e6ab6a23 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -43,6 +43,8 @@ dependencies: path: ../packages/mq_storage/ mq_ci_keys: path: ../packages/mq_ci_keys/ + mq_either: + path: ../packages/mq_either/ # flutter_native_splash: ^2.4.0 dev_dependencies: diff --git a/packages/mq_either/pubspec.yaml b/packages/mq_either/pubspec.yaml index 209bb683..37dc65d3 100644 --- a/packages/mq_either/pubspec.yaml +++ b/packages/mq_either/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: ^3.4.0 dependencies: - meta: ^1.15.0 + meta: ^1.12.0 dev_dependencies: mocktail: ^1.0.4