diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..73d1f98 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,17 @@ +name: deploy +on: + push: + branches: [ master ] +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: subosito/flutter-action@v1 + with: + channel: stable + - run: flutter pub get + - run: flutter format --set-exit-if-changed . + - run: flutter analyze --fatal-infos + - run: flutter test + - uses: erickzanardo/flutter-gh-pages@v2 diff --git a/.gitignore b/.gitignore index e2c5be1..53ee6c2 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ app.*.map.json # Openapi java generator openapi/openapi-generator-cli.jar + +windows \ No newline at end of file diff --git a/README.md b/README.md index d571116..5441eb2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,48 @@ -# Gestión UH +

+ Gestión UH +

-A UH managment app. +

+ +

-[![tests](https://github.com/NODO-UH/gestionapp/actions/workflows/tests.yml/badge.svg)](https://github.com/NODO-UH/gestionapp/actions/workflows/tests.yml) [![Codemagic build status](https://api.codemagic.io/apps/607a1a18d35b7a12ffb6c7dc/607a1a18d35b7a12ffb6c7db/status_badge.svg)](https://codemagic.io/apps/607a1a18d35b7a12ffb6c7dc/607a1a18d35b7a12ffb6c7db/latest_build) +

+ Aplicación para la gestión electrónica en la Universidad de La Habana. +

+ +

+ + tests + + + codemagic + + + lint + +

+ +
+ +### Principales funcionalidades + +- Creación del perfil. +- Consultar la cuota de Internet. +- Consultar el espacio restante del buzón de Correo. + +### Desarrolladores + +1. Nodo Central de Red - UH + - Jesús Luis Guerrero Campins - Infraestructura y Conectividad + - [Máximo Alejandro Alfonso Fernández - Infraestructura y Conectividad](https://github.com/maximoalejandro) + - [Andy González Peña - Infraestructura y Conectividad](https://github.com/andyglez) + - [Juan Jose Roque Cires - Desarrollador de Servicios](https://github.com/jr638091) + - [Christian Rodriguez Diaz - Desarrollador de Servicios](https://github.com/WrathXL) +2. Grupo de Redes y Sistemas - UH + - [Adrian Tubal Páez Ruiz - Desarrollador de Servicios](https://github.com/stdevAdrianPaez) + - [Marcos Antonio Maceo Reyes - Desarrollador de Servicios](https://github.com/stdevMac) + - [Roberto Marti Cedeño - Desarrollador](https://github.com/rmarticedeno) +3. Facultad de Matemática y Computación - UH + - [Carlos Bermúdez Porto - Desarrollador](https://github.com/cbermudez97) + - [Leonel Alejandro García López - Desarrollador](https://github.com/lagcleaner) + - [Leynier Gutiérrez González - Desarrollador](https://github.com/leynier) diff --git a/analysis_options.yaml b/analysis_options.yaml index ed0d062..a3258d1 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,5 +1,14 @@ include: package:lint/analysis_options.yaml +analyzer: + exclude: + - build/** + - lib/generated_plugin_registrant.dart + - lib/**/*.g.dart + - lib/**/*.freezed.dart + strong-mode: + implicit-casts: false + linter: rules: always_use_package_imports: true diff --git a/android/app/src/main/res/drawable-hdpi/splash.png b/android/app/src/main/res/drawable-hdpi/splash.png index 2e879a7..aa75bb7 100644 Binary files a/android/app/src/main/res/drawable-hdpi/splash.png and b/android/app/src/main/res/drawable-hdpi/splash.png differ diff --git a/android/app/src/main/res/drawable-mdpi/splash.png b/android/app/src/main/res/drawable-mdpi/splash.png index 9f44cae..41c0dfa 100644 Binary files a/android/app/src/main/res/drawable-mdpi/splash.png and b/android/app/src/main/res/drawable-mdpi/splash.png differ diff --git a/android/app/src/main/res/drawable-xhdpi/splash.png b/android/app/src/main/res/drawable-xhdpi/splash.png index bea1acb..a42873f 100644 Binary files a/android/app/src/main/res/drawable-xhdpi/splash.png and b/android/app/src/main/res/drawable-xhdpi/splash.png differ diff --git a/android/app/src/main/res/drawable-xxhdpi/splash.png b/android/app/src/main/res/drawable-xxhdpi/splash.png index 90147d7..18465be 100644 Binary files a/android/app/src/main/res/drawable-xxhdpi/splash.png and b/android/app/src/main/res/drawable-xxhdpi/splash.png differ diff --git a/android/app/src/main/res/drawable-xxxhdpi/splash.png b/android/app/src/main/res/drawable-xxxhdpi/splash.png index 583188a..30a6888 100644 Binary files a/android/app/src/main/res/drawable-xxxhdpi/splash.png and b/android/app/src/main/res/drawable-xxxhdpi/splash.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/launcher_icon.png b/android/app/src/main/res/mipmap-xxhdpi/launcher_icon.png index 8db3b90..2b8fe5d 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/launcher_icon.png and b/android/app/src/main/res/mipmap-xxhdpi/launcher_icon.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.png b/android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.png index 38584b3..7aa597c 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.png and b/android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.png differ diff --git a/assets/images/ico.png b/assets/images/ico.png deleted file mode 100644 index 6cacf10..0000000 Binary files a/assets/images/ico.png and /dev/null differ diff --git a/assets/images/icon.png b/assets/images/icon.png new file mode 100644 index 0000000..39edcbb Binary files /dev/null and b/assets/images/icon.png differ diff --git a/assets/images/logo-uh.png b/assets/images/logo-uh.png index 79bf89a..6a0eaab 100644 Binary files a/assets/images/logo-uh.png and b/assets/images/logo-uh.png differ diff --git a/assets/images/splash.png b/assets/images/splash.png index 541438e..8bbe03a 100644 Binary files a/assets/images/splash.png and b/assets/images/splash.png differ diff --git a/assets/images/splash2.png b/assets/images/splash2.png index 1e18945..8f3e7e5 100644 Binary files a/assets/images/splash2.png and b/assets/images/splash2.png differ diff --git a/banner.png b/banner.png new file mode 100644 index 0000000..2acf8b1 Binary files /dev/null and b/banner.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png index 96a5f6f..717f520 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png index 96a5f6f..717f520 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png index cf8cce3..a39af26 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png index 01c3cc3..9203ee5 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png index eef6d30..27cc6b3 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png index 057949d..3c30181 100644 Binary files a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png index ec777ec..751630f 100644 Binary files a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png differ diff --git a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png index 583188a..30a6888 100644 Binary files a/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png and b/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png differ diff --git a/lib/app.dart b/lib/app.dart deleted file mode 100644 index acdcf5d..0000000 --- a/lib/app.dart +++ /dev/null @@ -1,110 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/deps_injector.dart'; -import 'package:gestionuh/src/data/repository/auth_repository/auth_repository.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/pages.dart'; -import 'package:gestionuh/src/presentation/pages/about_page.dart'; -import 'package:gestionuh/src/presentation/pages/register_page.dart'; -import 'package:gestionuh/src/presentation/theme.dart'; -import 'package:gestionuh/src/utils/constants.dart'; -import 'package:gestionuh/src/utils/constants/routes.dart'; - -class GestionUhApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - title: Constants.appName, - theme: gestionuhLightTheme, - debugShowCheckedModeBanner: Constants.testMode, - onGenerateRoute: (settings) { - switch (settings.name) { - case LOGIN_ROUTE_NAME: - final authRepo = di(); - if (authRepo.logged) { - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di()..add(QuotaInitialized()), - child: const QuotaPage(), - ), - ); - } - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di(), - child: const LoginPage(), - ), - ); - case QUOTA_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di()..add(QuotaInitialized()), - child: const QuotaPage(), - ), - ); - case PROFILE_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di()..add(ProfileInitialized()), - child: const ProfilePage(), - ), - ); - case MAIL_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di()..add(MailQuotaInitialized()), - child: const MailQuotaPage(), - ), - ); - case RESET_PASSWORD_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di(), - child: const ResetPasswordPage(), - ), - ); - case REGISTER_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => Overlay( - initialEntries: [ - OverlayEntry(builder: (context) { - return BlocProvider( - create: (_) => di()..add(QuestionsRequestedRegister()), - child: const RegisterPage(), - ); - }), - ], - ), - ); - case ABOUT_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => const AboutInformationPage(), - ); - case RECOVER_PASSWORD_ROUTE_NAME: - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di(), - child: RecoverPasswordPage(), - ), - ); - default: - final authRepo = di(); - if (authRepo.logged) { - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di()..add(ProfileInitialized()), - child: const ProfilePage(), - ), - ); - } - return MaterialPageRoute( - builder: (_) => BlocProvider( - create: (_) => di(), - child: const LoginPage(), - ), - ); - } - }, - ); - } -} diff --git a/lib/deps_injector.dart b/lib/deps_injector.dart deleted file mode 100644 index 1dff131..0000000 --- a/lib/deps_injector.dart +++ /dev/null @@ -1,103 +0,0 @@ -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:gestionuh/src/data/api/api.dart'; -import 'package:gestionuh/src/data/local.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:get_it/get_it.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - -final di = GetIt.instance; - -Future init() async { - //Data Providers - di.registerSingleton(GestionApi()); - - final sharedPrefs = await SharedPreferences.getInstance(); - di.registerSingleton(sharedPrefs); - - di.registerLazySingleton( - () => const FlutterSecureStorage(), - ); - - di.registerLazySingleton( - () => LocalStorage( - prefs: di(), - secureStorage: di(), - ), - ); - - //Repositories - di.registerLazySingleton( - () => AuthRepository( - api: di(), - localStorage: di(), - ), - ); - - di.registerLazySingleton( - () => QuotasRepository( - api: di(), - ), - ); - - di.registerLazySingleton( - () => MailQuotasRepository( - api: di(), - ), - ); - - di.registerLazySingleton( - () => ProfileRepository( - api: di(), - ), - ); - - di.registerLazySingleton( - () => RecoverPasswordRepository( - api: di(), - ), - ); - - //Blocs - di.registerFactory( - () => LoginBloc( - authRepository: di(), - ), - ); - - di.registerFactory( - () => QuotaBloc( - quotasRepository: di(), - ), - ); - - di.registerFactory( - () => ResetPasswordBloc( - authRepository: di(), - ), - ); - - di.registerFactory( - () => MailQuotaBloc( - mailQuotasRepository: di(), - ), - ); - - di.registerFactory( - () => RecoverPasswordBloc( - recoverPasswordRepository: di(), - ), - ); - - di.registerFactory( - () => RegisterBloc( - repository: di(), - ), - ); - - di.registerFactory( - () => ProfileBloc( - profileRepository: di(), - ), - ); -} diff --git a/lib/main.dart b/lib/main.dart index 76adcfe..100d3fa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,18 +1,19 @@ import 'package:flutter/material.dart'; -import 'package:gestionuh/app.dart'; -import 'package:gestionuh/deps_injector.dart'; -import 'package:gestionuh/src/data/repository/auth_repository/auth_repository.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/app.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/dependencies.dart'; +import 'package:gestionuh/src/utils/configurations/configure_nonweb.dart' + if (dart.library.html) 'package:gestionuh/src/utils/configurations/configure_web.dart'; +import 'package:gestionuh/src/utils/simple_bloc_observer.dart'; +import 'package:get_it/get_it.dart'; Future main() async { - await initialize(); - runApp(GestionUhApp()); -} - -Future initialize() async { WidgetsFlutterBinding.ensureInitialized(); - - await init(); - + configureApp(); + Bloc.observer = SimpleBlocObserver(); + await DependencyInjection.init(); // Load user credentials - await di().initialize(); + await GetIt.I().initialize(); + runApp(GestionUhApp()); } diff --git a/lib/src/app.dart b/lib/src/app.dart new file mode 100644 index 0000000..6ac5c58 --- /dev/null +++ b/lib/src/app.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; +import 'package:gestionuh/src/presentation/theme/theme.dart'; +import 'package:gestionuh/src/router.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; + +class GestionUhApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + title: Constants.appName, + theme: gestionuhLightTheme, + debugShowCheckedModeBanner: Constants.testMode, + onGenerateRoute: RouterNavigation.onGenerateRoute, + ); + } +} diff --git a/lib/src/data/api/api.dart b/lib/src/data/api/api.dart index 0e4119b..a832a02 100644 --- a/lib/src/data/api/api.dart +++ b/lib/src/data/api/api.dart @@ -1,8 +1,9 @@ import 'dart:convert'; import 'package:dio/dio.dart'; -import 'package:gestionuh/src/data/models.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; typedef ClassBuilder = T Function( Map json); @@ -27,7 +28,7 @@ class GestionApi { final Auth response = Auth(); if (userName == null || password == null) { - response.error = 'Missing User Name or Password'; + response.error = 'Missing User Name or Password'; // dead code return response; } @@ -138,7 +139,7 @@ class GestionApi { ); } - Future resetPassword(String newPassw) async { + Future resetPassword(String currentPassw, String newPassw) async { if (Constants.testMode) return Status(status: true); Status response; @@ -251,7 +252,7 @@ class GestionApi { queryParameters: queryParams, ); } catch (error) { - target.error = Errors.retrieveError(error.toString()); + target.error = Errors.ConnectionError; return target; } @@ -265,7 +266,7 @@ class GestionApi { target = builder(jsonDecode(response.data!) as Map); } } catch (e) { - target.error = e.toString(); + target.error = Errors.DefaultError; } } diff --git a/lib/src/data/enums/enums.dart b/lib/src/data/enums/enums.dart new file mode 100644 index 0000000..28ee91f --- /dev/null +++ b/lib/src/data/enums/enums.dart @@ -0,0 +1 @@ +export 'home_item_enum.dart'; diff --git a/lib/src/data/enums/home_item_enum.dart b/lib/src/data/enums/home_item_enum.dart new file mode 100644 index 0000000..c4aa248 --- /dev/null +++ b/lib/src/data/enums/home_item_enum.dart @@ -0,0 +1,9 @@ +enum HomeItemEnum { + Separator, + Profile, + Quota, + MailQuota, + ResetPassword, + Logout, + AboutUs, +} diff --git a/lib/src/data/local.dart b/lib/src/data/local.dart deleted file mode 100644 index a8d95ab..0000000 --- a/lib/src/data/local.dart +++ /dev/null @@ -1 +0,0 @@ -export 'local/local_storage.dart'; diff --git a/lib/src/data/local/local_storage.dart b/lib/src/data/local/local_storage.dart index f686a6c..5840f09 100644 --- a/lib/src/data/local/local_storage.dart +++ b/lib/src/data/local/local_storage.dart @@ -1,5 +1,8 @@ +import 'dart:io' show Platform; + +import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; import 'package:shared_preferences/shared_preferences.dart'; abstract class ILocalStorage { @@ -8,6 +11,8 @@ abstract class ILocalStorage { bool isLogged(); + bool get isSecureStorageAvailable; + Future?> getCredentials(); Future updateCredentials({ @@ -33,8 +38,15 @@ class LocalStorage implements ILocalStorage { required this.secureStorage, }); + @override + bool get isSecureStorageAvailable => + !kIsWeb && (Platform.isAndroid || Platform.isIOS || Platform.isLinux); + @override Future loadSession() async { + if (!isSecureStorageAvailable) { + return; + } if (prefs.containsKey(USER_LOGGED_INTO) && prefs.getBool(USER_LOGGED_INTO)!) { final info = await secureStorage.readAll(); @@ -71,7 +83,7 @@ class LocalStorage implements ILocalStorage { bool isLoggedInto = true, bool persist = false, }) async { - if (persist) { + if (persist && isSecureStorageAvailable) { await secureStorage.write(key: USER_NAME, value: userName); await secureStorage.write(key: USER_PASSWORD, value: password); await prefs.setBool(USER_LOGGED_INTO, isLoggedInto); @@ -88,11 +100,13 @@ class LocalStorage implements ILocalStorage { Future invalidateCredentials() async { await prefs.setBool(USER_LOGGED_INTO, false); await prefs.setBool(USER_REMEMBERME, false); - if (await secureStorage.containsKey(key: USER_NAME)) { - await secureStorage.delete(key: USER_NAME); - } - if (await secureStorage.containsKey(key: USER_PASSWORD)) { - await secureStorage.delete(key: USER_PASSWORD); + if (isSecureStorageAvailable) { + if (await secureStorage.containsKey(key: USER_NAME)) { + await secureStorage.delete(key: USER_NAME); + } + if (await secureStorage.containsKey(key: USER_PASSWORD)) { + await secureStorage.delete(key: USER_PASSWORD); + } } sessionData.isLoggedInto = false; sessionData.rememberMe = false; diff --git a/lib/src/data/models.dart b/lib/src/data/models.dart deleted file mode 100644 index 58f2398..0000000 --- a/lib/src/data/models.dart +++ /dev/null @@ -1,15 +0,0 @@ -export 'models/auth.dart'; -export 'models/base_model.dart'; -export 'models/error.dart'; -export 'models/login.dart'; -export 'models/mail_quota.dart'; -export 'models/pass_reset.dart'; -export 'models/password_edit_data.dart'; -export 'models/password_reset_data.dart'; -export 'models/password_reset_user_id.dart'; -export 'models/quota.dart'; -export 'models/security_questions.dart'; -export 'models/status.dart'; -export 'models/user_ci.dart'; -export 'models/user_data.dart'; -export 'models/user_id.dart'; diff --git a/lib/src/data/models/auth.dart b/lib/src/data/models/auth.dart index 33ca826..310f0ef 100644 --- a/lib/src/data/models/auth.dart +++ b/lib/src/data/models/auth.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'auth.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/error.dart b/lib/src/data/models/error.dart index cfef5e1..a1361b2 100644 --- a/lib/src/data/models/error.dart +++ b/lib/src/data/models/error.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'error.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/login.dart b/lib/src/data/models/login.dart index 8dadb47..b85ad69 100644 --- a/lib/src/data/models/login.dart +++ b/lib/src/data/models/login.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'login.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/mail_quota.dart b/lib/src/data/models/mail_quota.dart index df8ad54..9a8765f 100644 --- a/lib/src/data/models/mail_quota.dart +++ b/lib/src/data/models/mail_quota.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'mail_quota.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/models.dart b/lib/src/data/models/models.dart new file mode 100644 index 0000000..d66d294 --- /dev/null +++ b/lib/src/data/models/models.dart @@ -0,0 +1,14 @@ +export 'auth.dart'; +export 'error.dart'; +export 'login.dart'; +export 'mail_quota.dart'; +export 'pass_reset.dart'; +export 'password_edit_data.dart'; +export 'password_reset_data.dart'; +export 'password_reset_user_id.dart'; +export 'quota.dart'; +export 'security_questions.dart'; +export 'status.dart'; +export 'user_ci.dart'; +export 'user_data.dart'; +export 'user_id.dart'; diff --git a/lib/src/data/models/pass_reset.dart b/lib/src/data/models/pass_reset.dart index 8e66386..0b2672a 100644 --- a/lib/src/data/models/pass_reset.dart +++ b/lib/src/data/models/pass_reset.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'pass_reset.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/password_edit_data.dart b/lib/src/data/models/password_edit_data.dart index b507bb0..4cd9448 100644 --- a/lib/src/data/models/password_edit_data.dart +++ b/lib/src/data/models/password_edit_data.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'password_edit_data.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/password_reset_data.dart b/lib/src/data/models/password_reset_data.dart index 3b0cf4b..39ca0c3 100644 --- a/lib/src/data/models/password_reset_data.dart +++ b/lib/src/data/models/password_reset_data.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'password_reset_data.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/password_reset_user_id.dart b/lib/src/data/models/password_reset_user_id.dart index e93c51e..b3e8668 100644 --- a/lib/src/data/models/password_reset_user_id.dart +++ b/lib/src/data/models/password_reset_user_id.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'password_reset_user_id.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/password_reset_user_id.g.dart b/lib/src/data/models/password_reset_user_id.g.dart index 799f55a..e34d72c 100644 --- a/lib/src/data/models/password_reset_user_id.g.dart +++ b/lib/src/data/models/password_reset_user_id.g.dart @@ -7,7 +7,9 @@ part of 'password_reset_user_id.dart'; // ************************************************************************** PasswordResetUserId _$PasswordResetUserIdFromJson(Map json) { - return PasswordResetUserId()..userId = json['userId'] as String?; + return PasswordResetUserId( + userId: json['userId'] as String?, + ); } Map _$PasswordResetUserIdToJson( diff --git a/lib/src/data/models/quota.dart b/lib/src/data/models/quota.dart index e8eeff7..4fdf58c 100644 --- a/lib/src/data/models/quota.dart +++ b/lib/src/data/models/quota.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'quota.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/security_questions.dart b/lib/src/data/models/security_questions.dart index 2aa4a69..a285fa2 100644 --- a/lib/src/data/models/security_questions.dart +++ b/lib/src/data/models/security_questions.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'security_questions.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/user_ci.dart b/lib/src/data/models/user_ci.dart index 10a6beb..e7a602a 100644 --- a/lib/src/data/models/user_ci.dart +++ b/lib/src/data/models/user_ci.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'user_ci.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/user_data.dart b/lib/src/data/models/user_data.dart index 4112b0e..558c471 100644 --- a/lib/src/data/models/user_data.dart +++ b/lib/src/data/models/user_data.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'user_data.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/models/user_id.dart b/lib/src/data/models/user_id.dart index da65fc3..66f7d17 100644 --- a/lib/src/data/models/user_id.dart +++ b/lib/src/data/models/user_id.dart @@ -1,6 +1,7 @@ -import 'package:gestionuh/src/data/models/base_model.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:gestionuh/src/data/models/base_model.dart'; + part 'user_id.g.dart'; @JsonSerializable(explicitToJson: true) diff --git a/lib/src/data/repository/auth_repository/auth_repository.dart b/lib/src/data/repositories/auth_repository.dart similarity index 79% rename from lib/src/data/repository/auth_repository/auth_repository.dart rename to lib/src/data/repositories/auth_repository.dart index 382b648..010f86d 100644 --- a/lib/src/data/repository/auth_repository/auth_repository.dart +++ b/lib/src/data/repositories/auth_repository.dart @@ -2,8 +2,9 @@ import 'dart:developer'; import 'package:gestionuh/src/data/api/api.dart'; import 'package:gestionuh/src/data/local/local_storage.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; import 'package:gestionuh/src/data/models/status.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; import 'package:gestionuh/src/utils/constants/storage_keys.dart'; class AuthRepository { @@ -50,8 +51,8 @@ class AuthRepository { return result; } catch (e) { log(e.toString()); + return Auth()..error = e.toString(); } - return null; } Future logout() async { @@ -59,9 +60,10 @@ class AuthRepository { await localStorage.invalidateCredentials(); } - Future resetPassword(String password) async { + Future resetPassword( + String currentPassword, String newPassword) async { try { - final status = await api.resetPassword(password); + final status = await api.resetPassword(currentPassword, newPassword); if (status.status == false) { return status; } @@ -69,21 +71,22 @@ class AuthRepository { final credentials = await localStorage.getCredentials(); if (credentials == null) { - throw Exception('Credentials is null.'); + return Status()..error = 'Cierre sesión, por favor'; + // exception ---> 'Credentials is null.'; } // save new password - api.setLogin(credentials[USER_NAME] as String, password); + api.setLogin(credentials[USER_NAME] as String, newPassword); localStorage.updateCredentials( userName: credentials[USER_NAME] as String, - password: password, + password: newPassword, persist: credentials[USER_REMEMBERME] as bool, ); return status; } catch (e) { log(e.toString()); - return Status(status: false); + return Status(status: false)..error = e.toString(); } } diff --git a/lib/src/data/repository/mail_quota_repository/mail_quota_repository.dart b/lib/src/data/repositories/mail_quota_repository.dart similarity index 72% rename from lib/src/data/repository/mail_quota_repository/mail_quota_repository.dart rename to lib/src/data/repositories/mail_quota_repository.dart index a08b252..ab3a876 100644 --- a/lib/src/data/repository/mail_quota_repository/mail_quota_repository.dart +++ b/lib/src/data/repositories/mail_quota_repository.dart @@ -1,7 +1,8 @@ import 'dart:developer'; import 'package:gestionuh/src/data/api/api.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; class MailQuotasRepository { final GestionApi api; @@ -21,6 +22,6 @@ class MailQuotasRepository { } catch (e) { log(e.toString()); } - return null; + return MailQuota()..error = Errors.DefaultError; } } diff --git a/lib/src/data/repository/profile_repository/profile_repository.dart b/lib/src/data/repositories/profile_repository.dart similarity index 89% rename from lib/src/data/repository/profile_repository/profile_repository.dart rename to lib/src/data/repositories/profile_repository.dart index c5656b7..0914d01 100644 --- a/lib/src/data/repository/profile_repository/profile_repository.dart +++ b/lib/src/data/repositories/profile_repository.dart @@ -1,7 +1,7 @@ import 'dart:developer'; import 'package:gestionuh/src/data/api/api.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; class ProfileRepository { final GestionApi api; diff --git a/lib/src/data/repository/quotas_repository/quotas_repository.dart b/lib/src/data/repositories/quotas_repository.dart similarity index 88% rename from lib/src/data/repository/quotas_repository/quotas_repository.dart rename to lib/src/data/repositories/quotas_repository.dart index 4e6e1db..328aae7 100644 --- a/lib/src/data/repository/quotas_repository/quotas_repository.dart +++ b/lib/src/data/repositories/quotas_repository.dart @@ -1,7 +1,7 @@ import 'dart:developer'; import 'package:gestionuh/src/data/api/api.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; class QuotasRepository { final GestionApi api; diff --git a/lib/src/data/repository/recover_password_repository/recover_password_repository.dart b/lib/src/data/repositories/recover_password_repository.dart similarity index 93% rename from lib/src/data/repository/recover_password_repository/recover_password_repository.dart rename to lib/src/data/repositories/recover_password_repository.dart index 38c0f7f..5194dc2 100644 --- a/lib/src/data/repository/recover_password_repository/recover_password_repository.dart +++ b/lib/src/data/repositories/recover_password_repository.dart @@ -1,7 +1,7 @@ import 'dart:developer'; import 'package:gestionuh/src/data/api/api.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; class RecoverPasswordRepository { final GestionApi api; diff --git a/lib/src/data/repositories/repositories.dart b/lib/src/data/repositories/repositories.dart new file mode 100644 index 0000000..b67bb7f --- /dev/null +++ b/lib/src/data/repositories/repositories.dart @@ -0,0 +1,6 @@ +export 'auth_repository.dart'; +export 'mail_quota_repository.dart'; +export 'profile_repository.dart'; +export 'quotas_repository.dart'; +export 'recover_password_repository.dart'; +export 'version_repository.dart'; diff --git a/lib/src/data/repositories/version_repository.dart b/lib/src/data/repositories/version_repository.dart new file mode 100644 index 0000000..dd82852 --- /dev/null +++ b/lib/src/data/repositories/version_repository.dart @@ -0,0 +1,10 @@ +import 'package:package_info_plus/package_info_plus.dart'; + +class VersionRepository { + PackageInfo? _packageInfo; + + Future getVersion() async { + _packageInfo ??= await PackageInfo.fromPlatform(); + return _packageInfo!.version; + } +} diff --git a/lib/src/data/repository.dart b/lib/src/data/repository.dart deleted file mode 100644 index 2d3bebc..0000000 --- a/lib/src/data/repository.dart +++ /dev/null @@ -1,5 +0,0 @@ -export 'repository/auth_repository/auth_repository.dart'; -export 'repository/mail_quota_repository/mail_quota_repository.dart'; -export 'repository/profile_repository/profile_repository.dart'; -export 'repository/quotas_repository/quotas_repository.dart'; -export 'repository/recover_password_repository/recover_password_repository.dart'; diff --git a/lib/src/dependencies.dart b/lib/src/dependencies.dart new file mode 100644 index 0000000..0555bcb --- /dev/null +++ b/lib/src/dependencies.dart @@ -0,0 +1,116 @@ +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:gestionuh/src/data/api/api.dart'; +import 'package:gestionuh/src/data/local/local_storage.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:get_it/get_it.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class DependencyInjection { + static Future init() async { + final I = GetIt.I; + + // Data Providers + I.registerSingleton(GestionApi()); + + final sharedPrefs = await SharedPreferences.getInstance(); + I.registerSingleton(sharedPrefs); + + I.registerLazySingleton( + () => const FlutterSecureStorage(), + ); + + I.registerLazySingleton( + () => LocalStorage( + prefs: I(), + secureStorage: I(), + ), + ); + + // Repositories + I.registerLazySingleton( + () => AuthRepository( + api: I(), + localStorage: I(), + ), + ); + + I.registerLazySingleton( + () => QuotasRepository( + api: I(), + ), + ); + + I.registerLazySingleton( + () => MailQuotasRepository( + api: I(), + ), + ); + + I.registerLazySingleton( + () => ProfileRepository( + api: I(), + ), + ); + + I.registerLazySingleton( + () => RecoverPasswordRepository( + api: I(), + ), + ); + + I.registerLazySingleton( + () => VersionRepository(), + ); + + // Blocs + I.registerFactory( + () => HomeBloc( + authRepository: I(), + profileRepository: I(), + ), + ); + + I.registerFactory( + () => LoginBloc( + authRepository: I(), + ), + ); + + I.registerFactory( + () => QuotaBloc( + quotasRepository: I(), + ), + ); + + I.registerFactory( + () => ResetPasswordBloc( + authRepository: I(), + ), + ); + + I.registerFactory( + () => MailQuotaBloc( + mailQuotasRepository: I(), + ), + ); + + I.registerFactory( + () => RecoverPasswordBloc( + recoverPasswordRepository: I(), + ), + ); + + I.registerFactory( + () => RegisterBloc( + repository: I(), + ), + ); + + I.registerFactory( + () => ProfileBloc( + profileRepository: I(), + ), + ); + } +} diff --git a/lib/src/presentation/blocs.dart b/lib/src/presentation/blocs.dart deleted file mode 100644 index 1c3d41e..0000000 --- a/lib/src/presentation/blocs.dart +++ /dev/null @@ -1,7 +0,0 @@ -export 'blocs/login_bloc/login_bloc.dart'; -export 'blocs/mail_quota_bloc/mail_quota_bloc.dart'; -export 'blocs/profile_bloc/profile_bloc.dart'; -export 'blocs/quota_bloc/quota_bloc.dart'; -export 'blocs/recover_password_bloc/recover_password_bloc.dart'; -export 'blocs/register_bloc/register_bloc.dart'; -export 'blocs/reset_password_bloc/resetpassword_bloc.dart'; diff --git a/lib/src/presentation/blocs/blocs.dart b/lib/src/presentation/blocs/blocs.dart new file mode 100644 index 0000000..d202b28 --- /dev/null +++ b/lib/src/presentation/blocs/blocs.dart @@ -0,0 +1,8 @@ +export 'home_bloc/home_bloc.dart'; +export 'login_bloc/login_bloc.dart'; +export 'mail_quota_bloc/mail_quota_bloc.dart'; +export 'profile_bloc/profile_bloc.dart'; +export 'quota_bloc/quota_bloc.dart'; +export 'recover_password_bloc/recover_password_bloc.dart'; +export 'register_bloc/register_bloc.dart'; +export 'reset_password_bloc/resetpassword_bloc.dart'; diff --git a/lib/src/presentation/blocs/home_bloc/home_bloc.dart b/lib/src/presentation/blocs/home_bloc/home_bloc.dart new file mode 100644 index 0000000..8657759 --- /dev/null +++ b/lib/src/presentation/blocs/home_bloc/home_bloc.dart @@ -0,0 +1,89 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:gestionuh/src/data/enums/enums.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; + +part 'home_bloc.freezed.dart'; +part 'home_event.dart'; +part 'home_state.dart'; + +class HomeBloc extends Bloc { + final AuthRepository authRepository; + final ProfileRepository profileRepository; + HomeBloc({ + required this.authRepository, + required this.profileRepository, + }) : super(const HomeState.loading()); + + @override + Stream mapEventToState( + HomeEvent event, + ) async* { + yield* event.when( + loadProfile: () async* { + yield const HomeState.loading(); + final result = await profileRepository.getUserData(); + if (result == null) { + yield const HomeState.error(Errors.DefaultError); + } else if (result.error != null) { + yield HomeState.error(result.error!); + } else { + add(HomeEvent.goToProfile(result)); + } + }, + goToProfile: (profile) async* { + yield HomeState.profile( + profile, + _getItemsByProfile(profile), + ); + }, + goToQuota: (profile) async* { + yield HomeState.quota( + profile, + _getItemsByProfile(profile), + ); + }, + goToMailQuota: (profile) async* { + yield HomeState.mailQuota( + profile, + _getItemsByProfile(profile), + ); + }, + goToResetPassword: (profile) async* { + yield HomeState.resetPassword( + profile, + _getItemsByProfile(profile), + ); + }, + goToAboutUs: (profile) async* { + yield HomeState.aboutUs( + profile, + _getItemsByProfile(profile), + ); + }, + logout: () async* { + yield const HomeState.loading(); + await authRepository.logout(); + yield const HomeState.logout(); + }, + ); + } + + List _getItemsByProfile(UserData profile) { + return [ + HomeItemEnum.Profile, + if (profile.hasInternet ?? false) HomeItemEnum.Quota, + if (profile.hasEmail ?? false) HomeItemEnum.MailQuota, + HomeItemEnum.ResetPassword, + HomeItemEnum.Logout, + HomeItemEnum.Separator, + HomeItemEnum.AboutUs, + ]; + } +} diff --git a/lib/src/presentation/blocs/home_bloc/home_bloc.freezed.dart b/lib/src/presentation/blocs/home_bloc/home_bloc.freezed.dart new file mode 100644 index 0000000..ae92827 --- /dev/null +++ b/lib/src/presentation/blocs/home_bloc/home_bloc.freezed.dart @@ -0,0 +1,2396 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'home_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$HomeEventTearOff { + const _$HomeEventTearOff(); + + _LoadProfile loadProfile() { + return const _LoadProfile(); + } + + _SendLogout logout() { + return const _SendLogout(); + } + + _GoToProfile goToProfile(UserData profile) { + return _GoToProfile( + profile, + ); + } + + _GoToQuota goToQuota(UserData profile) { + return _GoToQuota( + profile, + ); + } + + _GoToMailQuota goToMailQuota(UserData profile) { + return _GoToMailQuota( + profile, + ); + } + + _GoToResetPassword goToResetPassword(UserData profile) { + return _GoToResetPassword( + profile, + ); + } + + _GoToAboutUs goToAboutUs(UserData profile) { + return _GoToAboutUs( + profile, + ); + } +} + +/// @nodoc +const $HomeEvent = _$HomeEventTearOff(); + +/// @nodoc +mixin _$HomeEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $HomeEventCopyWith<$Res> { + factory $HomeEventCopyWith(HomeEvent value, $Res Function(HomeEvent) then) = + _$HomeEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$HomeEventCopyWithImpl<$Res> implements $HomeEventCopyWith<$Res> { + _$HomeEventCopyWithImpl(this._value, this._then); + + final HomeEvent _value; + // ignore: unused_field + final $Res Function(HomeEvent) _then; +} + +/// @nodoc +abstract class _$LoadProfileCopyWith<$Res> { + factory _$LoadProfileCopyWith( + _LoadProfile value, $Res Function(_LoadProfile) then) = + __$LoadProfileCopyWithImpl<$Res>; +} + +/// @nodoc +class __$LoadProfileCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$LoadProfileCopyWith<$Res> { + __$LoadProfileCopyWithImpl( + _LoadProfile _value, $Res Function(_LoadProfile) _then) + : super(_value, (v) => _then(v as _LoadProfile)); + + @override + _LoadProfile get _value => super._value as _LoadProfile; +} + +/// @nodoc + +class _$_LoadProfile with DiagnosticableTreeMixin implements _LoadProfile { + const _$_LoadProfile(); + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.loadProfile()'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties..add(DiagnosticsProperty('type', 'HomeEvent.loadProfile')); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _LoadProfile); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return loadProfile(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (loadProfile != null) { + return loadProfile(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return loadProfile(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (loadProfile != null) { + return loadProfile(this); + } + return orElse(); + } +} + +abstract class _LoadProfile implements HomeEvent { + const factory _LoadProfile() = _$_LoadProfile; +} + +/// @nodoc +abstract class _$SendLogoutCopyWith<$Res> { + factory _$SendLogoutCopyWith( + _SendLogout value, $Res Function(_SendLogout) then) = + __$SendLogoutCopyWithImpl<$Res>; +} + +/// @nodoc +class __$SendLogoutCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$SendLogoutCopyWith<$Res> { + __$SendLogoutCopyWithImpl( + _SendLogout _value, $Res Function(_SendLogout) _then) + : super(_value, (v) => _then(v as _SendLogout)); + + @override + _SendLogout get _value => super._value as _SendLogout; +} + +/// @nodoc + +class _$_SendLogout with DiagnosticableTreeMixin implements _SendLogout { + const _$_SendLogout(); + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.logout()'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties..add(DiagnosticsProperty('type', 'HomeEvent.logout')); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _SendLogout); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return logout(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (logout != null) { + return logout(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return logout(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (logout != null) { + return logout(this); + } + return orElse(); + } +} + +abstract class _SendLogout implements HomeEvent { + const factory _SendLogout() = _$_SendLogout; +} + +/// @nodoc +abstract class _$GoToProfileCopyWith<$Res> { + factory _$GoToProfileCopyWith( + _GoToProfile value, $Res Function(_GoToProfile) then) = + __$GoToProfileCopyWithImpl<$Res>; + $Res call({UserData profile}); +} + +/// @nodoc +class __$GoToProfileCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$GoToProfileCopyWith<$Res> { + __$GoToProfileCopyWithImpl( + _GoToProfile _value, $Res Function(_GoToProfile) _then) + : super(_value, (v) => _then(v as _GoToProfile)); + + @override + _GoToProfile get _value => super._value as _GoToProfile; + + @override + $Res call({ + Object? profile = freezed, + }) { + return _then(_GoToProfile( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + )); + } +} + +/// @nodoc + +class _$_GoToProfile with DiagnosticableTreeMixin implements _GoToProfile { + const _$_GoToProfile(this.profile); + + @override + final UserData profile; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.goToProfile(profile: $profile)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeEvent.goToProfile')) + ..add(DiagnosticsProperty('profile', profile)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GoToProfile && + (identical(other.profile, profile) || + const DeepCollectionEquality().equals(other.profile, profile))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(profile); + + @JsonKey(ignore: true) + @override + _$GoToProfileCopyWith<_GoToProfile> get copyWith => + __$GoToProfileCopyWithImpl<_GoToProfile>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return goToProfile(profile); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (goToProfile != null) { + return goToProfile(profile); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return goToProfile(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (goToProfile != null) { + return goToProfile(this); + } + return orElse(); + } +} + +abstract class _GoToProfile implements HomeEvent { + const factory _GoToProfile(UserData profile) = _$_GoToProfile; + + UserData get profile => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$GoToProfileCopyWith<_GoToProfile> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$GoToQuotaCopyWith<$Res> { + factory _$GoToQuotaCopyWith( + _GoToQuota value, $Res Function(_GoToQuota) then) = + __$GoToQuotaCopyWithImpl<$Res>; + $Res call({UserData profile}); +} + +/// @nodoc +class __$GoToQuotaCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$GoToQuotaCopyWith<$Res> { + __$GoToQuotaCopyWithImpl(_GoToQuota _value, $Res Function(_GoToQuota) _then) + : super(_value, (v) => _then(v as _GoToQuota)); + + @override + _GoToQuota get _value => super._value as _GoToQuota; + + @override + $Res call({ + Object? profile = freezed, + }) { + return _then(_GoToQuota( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + )); + } +} + +/// @nodoc + +class _$_GoToQuota with DiagnosticableTreeMixin implements _GoToQuota { + const _$_GoToQuota(this.profile); + + @override + final UserData profile; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.goToQuota(profile: $profile)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeEvent.goToQuota')) + ..add(DiagnosticsProperty('profile', profile)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GoToQuota && + (identical(other.profile, profile) || + const DeepCollectionEquality().equals(other.profile, profile))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(profile); + + @JsonKey(ignore: true) + @override + _$GoToQuotaCopyWith<_GoToQuota> get copyWith => + __$GoToQuotaCopyWithImpl<_GoToQuota>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return goToQuota(profile); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (goToQuota != null) { + return goToQuota(profile); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return goToQuota(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (goToQuota != null) { + return goToQuota(this); + } + return orElse(); + } +} + +abstract class _GoToQuota implements HomeEvent { + const factory _GoToQuota(UserData profile) = _$_GoToQuota; + + UserData get profile => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$GoToQuotaCopyWith<_GoToQuota> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$GoToMailQuotaCopyWith<$Res> { + factory _$GoToMailQuotaCopyWith( + _GoToMailQuota value, $Res Function(_GoToMailQuota) then) = + __$GoToMailQuotaCopyWithImpl<$Res>; + $Res call({UserData profile}); +} + +/// @nodoc +class __$GoToMailQuotaCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$GoToMailQuotaCopyWith<$Res> { + __$GoToMailQuotaCopyWithImpl( + _GoToMailQuota _value, $Res Function(_GoToMailQuota) _then) + : super(_value, (v) => _then(v as _GoToMailQuota)); + + @override + _GoToMailQuota get _value => super._value as _GoToMailQuota; + + @override + $Res call({ + Object? profile = freezed, + }) { + return _then(_GoToMailQuota( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + )); + } +} + +/// @nodoc + +class _$_GoToMailQuota with DiagnosticableTreeMixin implements _GoToMailQuota { + const _$_GoToMailQuota(this.profile); + + @override + final UserData profile; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.goToMailQuota(profile: $profile)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeEvent.goToMailQuota')) + ..add(DiagnosticsProperty('profile', profile)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GoToMailQuota && + (identical(other.profile, profile) || + const DeepCollectionEquality().equals(other.profile, profile))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(profile); + + @JsonKey(ignore: true) + @override + _$GoToMailQuotaCopyWith<_GoToMailQuota> get copyWith => + __$GoToMailQuotaCopyWithImpl<_GoToMailQuota>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return goToMailQuota(profile); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (goToMailQuota != null) { + return goToMailQuota(profile); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return goToMailQuota(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (goToMailQuota != null) { + return goToMailQuota(this); + } + return orElse(); + } +} + +abstract class _GoToMailQuota implements HomeEvent { + const factory _GoToMailQuota(UserData profile) = _$_GoToMailQuota; + + UserData get profile => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$GoToMailQuotaCopyWith<_GoToMailQuota> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$GoToResetPasswordCopyWith<$Res> { + factory _$GoToResetPasswordCopyWith( + _GoToResetPassword value, $Res Function(_GoToResetPassword) then) = + __$GoToResetPasswordCopyWithImpl<$Res>; + $Res call({UserData profile}); +} + +/// @nodoc +class __$GoToResetPasswordCopyWithImpl<$Res> + extends _$HomeEventCopyWithImpl<$Res> + implements _$GoToResetPasswordCopyWith<$Res> { + __$GoToResetPasswordCopyWithImpl( + _GoToResetPassword _value, $Res Function(_GoToResetPassword) _then) + : super(_value, (v) => _then(v as _GoToResetPassword)); + + @override + _GoToResetPassword get _value => super._value as _GoToResetPassword; + + @override + $Res call({ + Object? profile = freezed, + }) { + return _then(_GoToResetPassword( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + )); + } +} + +/// @nodoc + +class _$_GoToResetPassword + with DiagnosticableTreeMixin + implements _GoToResetPassword { + const _$_GoToResetPassword(this.profile); + + @override + final UserData profile; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.goToResetPassword(profile: $profile)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeEvent.goToResetPassword')) + ..add(DiagnosticsProperty('profile', profile)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GoToResetPassword && + (identical(other.profile, profile) || + const DeepCollectionEquality().equals(other.profile, profile))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(profile); + + @JsonKey(ignore: true) + @override + _$GoToResetPasswordCopyWith<_GoToResetPassword> get copyWith => + __$GoToResetPasswordCopyWithImpl<_GoToResetPassword>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return goToResetPassword(profile); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (goToResetPassword != null) { + return goToResetPassword(profile); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return goToResetPassword(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (goToResetPassword != null) { + return goToResetPassword(this); + } + return orElse(); + } +} + +abstract class _GoToResetPassword implements HomeEvent { + const factory _GoToResetPassword(UserData profile) = _$_GoToResetPassword; + + UserData get profile => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$GoToResetPasswordCopyWith<_GoToResetPassword> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$GoToAboutUsCopyWith<$Res> { + factory _$GoToAboutUsCopyWith( + _GoToAboutUs value, $Res Function(_GoToAboutUs) then) = + __$GoToAboutUsCopyWithImpl<$Res>; + $Res call({UserData profile}); +} + +/// @nodoc +class __$GoToAboutUsCopyWithImpl<$Res> extends _$HomeEventCopyWithImpl<$Res> + implements _$GoToAboutUsCopyWith<$Res> { + __$GoToAboutUsCopyWithImpl( + _GoToAboutUs _value, $Res Function(_GoToAboutUs) _then) + : super(_value, (v) => _then(v as _GoToAboutUs)); + + @override + _GoToAboutUs get _value => super._value as _GoToAboutUs; + + @override + $Res call({ + Object? profile = freezed, + }) { + return _then(_GoToAboutUs( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + )); + } +} + +/// @nodoc + +class _$_GoToAboutUs with DiagnosticableTreeMixin implements _GoToAboutUs { + const _$_GoToAboutUs(this.profile); + + @override + final UserData profile; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeEvent.goToAboutUs(profile: $profile)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeEvent.goToAboutUs')) + ..add(DiagnosticsProperty('profile', profile)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _GoToAboutUs && + (identical(other.profile, profile) || + const DeepCollectionEquality().equals(other.profile, profile))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(profile); + + @JsonKey(ignore: true) + @override + _$GoToAboutUsCopyWith<_GoToAboutUs> get copyWith => + __$GoToAboutUsCopyWithImpl<_GoToAboutUs>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loadProfile, + required TResult Function() logout, + required TResult Function(UserData profile) goToProfile, + required TResult Function(UserData profile) goToQuota, + required TResult Function(UserData profile) goToMailQuota, + required TResult Function(UserData profile) goToResetPassword, + required TResult Function(UserData profile) goToAboutUs, + }) { + return goToAboutUs(profile); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loadProfile, + TResult Function()? logout, + TResult Function(UserData profile)? goToProfile, + TResult Function(UserData profile)? goToQuota, + TResult Function(UserData profile)? goToMailQuota, + TResult Function(UserData profile)? goToResetPassword, + TResult Function(UserData profile)? goToAboutUs, + required TResult orElse(), + }) { + if (goToAboutUs != null) { + return goToAboutUs(profile); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_LoadProfile value) loadProfile, + required TResult Function(_SendLogout value) logout, + required TResult Function(_GoToProfile value) goToProfile, + required TResult Function(_GoToQuota value) goToQuota, + required TResult Function(_GoToMailQuota value) goToMailQuota, + required TResult Function(_GoToResetPassword value) goToResetPassword, + required TResult Function(_GoToAboutUs value) goToAboutUs, + }) { + return goToAboutUs(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_LoadProfile value)? loadProfile, + TResult Function(_SendLogout value)? logout, + TResult Function(_GoToProfile value)? goToProfile, + TResult Function(_GoToQuota value)? goToQuota, + TResult Function(_GoToMailQuota value)? goToMailQuota, + TResult Function(_GoToResetPassword value)? goToResetPassword, + TResult Function(_GoToAboutUs value)? goToAboutUs, + required TResult orElse(), + }) { + if (goToAboutUs != null) { + return goToAboutUs(this); + } + return orElse(); + } +} + +abstract class _GoToAboutUs implements HomeEvent { + const factory _GoToAboutUs(UserData profile) = _$_GoToAboutUs; + + UserData get profile => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$GoToAboutUsCopyWith<_GoToAboutUs> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$HomeStateTearOff { + const _$HomeStateTearOff(); + + _Loading loading() { + return const _Loading(); + } + + _Error error(String message) { + return _Error( + message, + ); + } + + _Logout logout() { + return const _Logout(); + } + + _Profile profile(UserData profile, List items) { + return _Profile( + profile, + items, + ); + } + + _Quota quota(UserData profile, List items) { + return _Quota( + profile, + items, + ); + } + + _MailQuota mailQuota(UserData profile, List items) { + return _MailQuota( + profile, + items, + ); + } + + _ResetPassword resetPassword(UserData profile, List items) { + return _ResetPassword( + profile, + items, + ); + } + + _AboutUs aboutUs(UserData profile, List items) { + return _AboutUs( + profile, + items, + ); + } +} + +/// @nodoc +const $HomeState = _$HomeStateTearOff(); + +/// @nodoc +mixin _$HomeState { + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $HomeStateCopyWith<$Res> { + factory $HomeStateCopyWith(HomeState value, $Res Function(HomeState) then) = + _$HomeStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$HomeStateCopyWithImpl<$Res> implements $HomeStateCopyWith<$Res> { + _$HomeStateCopyWithImpl(this._value, this._then); + + final HomeState _value; + // ignore: unused_field + final $Res Function(HomeState) _then; +} + +/// @nodoc +abstract class _$LoadingCopyWith<$Res> { + factory _$LoadingCopyWith(_Loading value, $Res Function(_Loading) then) = + __$LoadingCopyWithImpl<$Res>; +} + +/// @nodoc +class __$LoadingCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$LoadingCopyWith<$Res> { + __$LoadingCopyWithImpl(_Loading _value, $Res Function(_Loading) _then) + : super(_value, (v) => _then(v as _Loading)); + + @override + _Loading get _value => super._value as _Loading; +} + +/// @nodoc + +class _$_Loading with DiagnosticableTreeMixin implements _Loading { + const _$_Loading(); + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.loading()'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties..add(DiagnosticsProperty('type', 'HomeState.loading')); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Loading); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return loading(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (loading != null) { + return loading(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return loading(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (loading != null) { + return loading(this); + } + return orElse(); + } +} + +abstract class _Loading implements HomeState { + const factory _Loading() = _$_Loading; +} + +/// @nodoc +abstract class _$ErrorCopyWith<$Res> { + factory _$ErrorCopyWith(_Error value, $Res Function(_Error) then) = + __$ErrorCopyWithImpl<$Res>; + $Res call({String message}); +} + +/// @nodoc +class __$ErrorCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$ErrorCopyWith<$Res> { + __$ErrorCopyWithImpl(_Error _value, $Res Function(_Error) _then) + : super(_value, (v) => _then(v as _Error)); + + @override + _Error get _value => super._value as _Error; + + @override + $Res call({ + Object? message = freezed, + }) { + return _then(_Error( + message == freezed + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_Error with DiagnosticableTreeMixin implements _Error { + const _$_Error(this.message); + + @override + final String message; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.error(message: $message)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.error')) + ..add(DiagnosticsProperty('message', message)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Error && + (identical(other.message, message) || + const DeepCollectionEquality().equals(other.message, message))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(message); + + @JsonKey(ignore: true) + @override + _$ErrorCopyWith<_Error> get copyWith => + __$ErrorCopyWithImpl<_Error>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return error(message); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (error != null) { + return error(message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return error(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (error != null) { + return error(this); + } + return orElse(); + } +} + +abstract class _Error implements HomeState { + const factory _Error(String message) = _$_Error; + + String get message => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$ErrorCopyWith<_Error> get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$LogoutCopyWith<$Res> { + factory _$LogoutCopyWith(_Logout value, $Res Function(_Logout) then) = + __$LogoutCopyWithImpl<$Res>; +} + +/// @nodoc +class __$LogoutCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$LogoutCopyWith<$Res> { + __$LogoutCopyWithImpl(_Logout _value, $Res Function(_Logout) _then) + : super(_value, (v) => _then(v as _Logout)); + + @override + _Logout get _value => super._value as _Logout; +} + +/// @nodoc + +class _$_Logout with DiagnosticableTreeMixin implements _Logout { + const _$_Logout(); + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.logout()'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties..add(DiagnosticsProperty('type', 'HomeState.logout')); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _Logout); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return logout(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (logout != null) { + return logout(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return logout(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (logout != null) { + return logout(this); + } + return orElse(); + } +} + +abstract class _Logout implements HomeState { + const factory _Logout() = _$_Logout; +} + +/// @nodoc +abstract class _$ProfileCopyWith<$Res> { + factory _$ProfileCopyWith(_Profile value, $Res Function(_Profile) then) = + __$ProfileCopyWithImpl<$Res>; + $Res call({UserData profile, List items}); +} + +/// @nodoc +class __$ProfileCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$ProfileCopyWith<$Res> { + __$ProfileCopyWithImpl(_Profile _value, $Res Function(_Profile) _then) + : super(_value, (v) => _then(v as _Profile)); + + @override + _Profile get _value => super._value as _Profile; + + @override + $Res call({ + Object? profile = freezed, + Object? items = freezed, + }) { + return _then(_Profile( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + items == freezed + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_Profile with DiagnosticableTreeMixin implements _Profile { + const _$_Profile(this.profile, this.items); + + @override + final UserData profile; + @override + final List items; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.profile(profile: $profile, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.profile')) + ..add(DiagnosticsProperty('profile', profile)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Profile && + (identical(other.profile, profile) || + const DeepCollectionEquality() + .equals(other.profile, profile)) && + (identical(other.items, items) || + const DeepCollectionEquality().equals(other.items, items))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(profile) ^ + const DeepCollectionEquality().hash(items); + + @JsonKey(ignore: true) + @override + _$ProfileCopyWith<_Profile> get copyWith => + __$ProfileCopyWithImpl<_Profile>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return profile(this.profile, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (profile != null) { + return profile(this.profile, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return profile(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (profile != null) { + return profile(this); + } + return orElse(); + } +} + +abstract class _Profile implements HomeState { + const factory _Profile(UserData profile, List items) = + _$_Profile; + + UserData get profile => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$ProfileCopyWith<_Profile> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$QuotaCopyWith<$Res> { + factory _$QuotaCopyWith(_Quota value, $Res Function(_Quota) then) = + __$QuotaCopyWithImpl<$Res>; + $Res call({UserData profile, List items}); +} + +/// @nodoc +class __$QuotaCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$QuotaCopyWith<$Res> { + __$QuotaCopyWithImpl(_Quota _value, $Res Function(_Quota) _then) + : super(_value, (v) => _then(v as _Quota)); + + @override + _Quota get _value => super._value as _Quota; + + @override + $Res call({ + Object? profile = freezed, + Object? items = freezed, + }) { + return _then(_Quota( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + items == freezed + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_Quota with DiagnosticableTreeMixin implements _Quota { + const _$_Quota(this.profile, this.items); + + @override + final UserData profile; + @override + final List items; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.quota(profile: $profile, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.quota')) + ..add(DiagnosticsProperty('profile', profile)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Quota && + (identical(other.profile, profile) || + const DeepCollectionEquality() + .equals(other.profile, profile)) && + (identical(other.items, items) || + const DeepCollectionEquality().equals(other.items, items))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(profile) ^ + const DeepCollectionEquality().hash(items); + + @JsonKey(ignore: true) + @override + _$QuotaCopyWith<_Quota> get copyWith => + __$QuotaCopyWithImpl<_Quota>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return quota(this.profile, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (quota != null) { + return quota(this.profile, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return quota(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (quota != null) { + return quota(this); + } + return orElse(); + } +} + +abstract class _Quota implements HomeState { + const factory _Quota(UserData profile, List items) = _$_Quota; + + UserData get profile => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$QuotaCopyWith<_Quota> get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$MailQuotaCopyWith<$Res> { + factory _$MailQuotaCopyWith( + _MailQuota value, $Res Function(_MailQuota) then) = + __$MailQuotaCopyWithImpl<$Res>; + $Res call({UserData profile, List items}); +} + +/// @nodoc +class __$MailQuotaCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$MailQuotaCopyWith<$Res> { + __$MailQuotaCopyWithImpl(_MailQuota _value, $Res Function(_MailQuota) _then) + : super(_value, (v) => _then(v as _MailQuota)); + + @override + _MailQuota get _value => super._value as _MailQuota; + + @override + $Res call({ + Object? profile = freezed, + Object? items = freezed, + }) { + return _then(_MailQuota( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + items == freezed + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_MailQuota with DiagnosticableTreeMixin implements _MailQuota { + const _$_MailQuota(this.profile, this.items); + + @override + final UserData profile; + @override + final List items; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.mailQuota(profile: $profile, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.mailQuota')) + ..add(DiagnosticsProperty('profile', profile)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _MailQuota && + (identical(other.profile, profile) || + const DeepCollectionEquality() + .equals(other.profile, profile)) && + (identical(other.items, items) || + const DeepCollectionEquality().equals(other.items, items))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(profile) ^ + const DeepCollectionEquality().hash(items); + + @JsonKey(ignore: true) + @override + _$MailQuotaCopyWith<_MailQuota> get copyWith => + __$MailQuotaCopyWithImpl<_MailQuota>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return mailQuota(this.profile, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (mailQuota != null) { + return mailQuota(this.profile, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return mailQuota(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (mailQuota != null) { + return mailQuota(this); + } + return orElse(); + } +} + +abstract class _MailQuota implements HomeState { + const factory _MailQuota(UserData profile, List items) = + _$_MailQuota; + + UserData get profile => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$MailQuotaCopyWith<_MailQuota> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$ResetPasswordCopyWith<$Res> { + factory _$ResetPasswordCopyWith( + _ResetPassword value, $Res Function(_ResetPassword) then) = + __$ResetPasswordCopyWithImpl<$Res>; + $Res call({UserData profile, List items}); +} + +/// @nodoc +class __$ResetPasswordCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$ResetPasswordCopyWith<$Res> { + __$ResetPasswordCopyWithImpl( + _ResetPassword _value, $Res Function(_ResetPassword) _then) + : super(_value, (v) => _then(v as _ResetPassword)); + + @override + _ResetPassword get _value => super._value as _ResetPassword; + + @override + $Res call({ + Object? profile = freezed, + Object? items = freezed, + }) { + return _then(_ResetPassword( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + items == freezed + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_ResetPassword with DiagnosticableTreeMixin implements _ResetPassword { + const _$_ResetPassword(this.profile, this.items); + + @override + final UserData profile; + @override + final List items; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.resetPassword(profile: $profile, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.resetPassword')) + ..add(DiagnosticsProperty('profile', profile)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _ResetPassword && + (identical(other.profile, profile) || + const DeepCollectionEquality() + .equals(other.profile, profile)) && + (identical(other.items, items) || + const DeepCollectionEquality().equals(other.items, items))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(profile) ^ + const DeepCollectionEquality().hash(items); + + @JsonKey(ignore: true) + @override + _$ResetPasswordCopyWith<_ResetPassword> get copyWith => + __$ResetPasswordCopyWithImpl<_ResetPassword>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return resetPassword(this.profile, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (resetPassword != null) { + return resetPassword(this.profile, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return resetPassword(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (resetPassword != null) { + return resetPassword(this); + } + return orElse(); + } +} + +abstract class _ResetPassword implements HomeState { + const factory _ResetPassword(UserData profile, List items) = + _$_ResetPassword; + + UserData get profile => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$ResetPasswordCopyWith<_ResetPassword> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$AboutUsCopyWith<$Res> { + factory _$AboutUsCopyWith(_AboutUs value, $Res Function(_AboutUs) then) = + __$AboutUsCopyWithImpl<$Res>; + $Res call({UserData profile, List items}); +} + +/// @nodoc +class __$AboutUsCopyWithImpl<$Res> extends _$HomeStateCopyWithImpl<$Res> + implements _$AboutUsCopyWith<$Res> { + __$AboutUsCopyWithImpl(_AboutUs _value, $Res Function(_AboutUs) _then) + : super(_value, (v) => _then(v as _AboutUs)); + + @override + _AboutUs get _value => super._value as _AboutUs; + + @override + $Res call({ + Object? profile = freezed, + Object? items = freezed, + }) { + return _then(_AboutUs( + profile == freezed + ? _value.profile + : profile // ignore: cast_nullable_to_non_nullable + as UserData, + items == freezed + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_AboutUs with DiagnosticableTreeMixin implements _AboutUs { + const _$_AboutUs(this.profile, this.items); + + @override + final UserData profile; + @override + final List items; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'HomeState.aboutUs(profile: $profile, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'HomeState.aboutUs')) + ..add(DiagnosticsProperty('profile', profile)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _AboutUs && + (identical(other.profile, profile) || + const DeepCollectionEquality() + .equals(other.profile, profile)) && + (identical(other.items, items) || + const DeepCollectionEquality().equals(other.items, items))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(profile) ^ + const DeepCollectionEquality().hash(items); + + @JsonKey(ignore: true) + @override + _$AboutUsCopyWith<_AboutUs> get copyWith => + __$AboutUsCopyWithImpl<_AboutUs>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() loading, + required TResult Function(String message) error, + required TResult Function() logout, + required TResult Function(UserData profile, List items) + profile, + required TResult Function(UserData profile, List items) quota, + required TResult Function(UserData profile, List items) + mailQuota, + required TResult Function(UserData profile, List items) + resetPassword, + required TResult Function(UserData profile, List items) + aboutUs, + }) { + return aboutUs(this.profile, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? loading, + TResult Function(String message)? error, + TResult Function()? logout, + TResult Function(UserData profile, List items)? profile, + TResult Function(UserData profile, List items)? quota, + TResult Function(UserData profile, List items)? mailQuota, + TResult Function(UserData profile, List items)? resetPassword, + TResult Function(UserData profile, List items)? aboutUs, + required TResult orElse(), + }) { + if (aboutUs != null) { + return aboutUs(this.profile, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Loading value) loading, + required TResult Function(_Error value) error, + required TResult Function(_Logout value) logout, + required TResult Function(_Profile value) profile, + required TResult Function(_Quota value) quota, + required TResult Function(_MailQuota value) mailQuota, + required TResult Function(_ResetPassword value) resetPassword, + required TResult Function(_AboutUs value) aboutUs, + }) { + return aboutUs(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Loading value)? loading, + TResult Function(_Error value)? error, + TResult Function(_Logout value)? logout, + TResult Function(_Profile value)? profile, + TResult Function(_Quota value)? quota, + TResult Function(_MailQuota value)? mailQuota, + TResult Function(_ResetPassword value)? resetPassword, + TResult Function(_AboutUs value)? aboutUs, + required TResult orElse(), + }) { + if (aboutUs != null) { + return aboutUs(this); + } + return orElse(); + } +} + +abstract class _AboutUs implements HomeState { + const factory _AboutUs(UserData profile, List items) = + _$_AboutUs; + + UserData get profile => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$AboutUsCopyWith<_AboutUs> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/home_bloc/home_event.dart b/lib/src/presentation/blocs/home_bloc/home_event.dart new file mode 100644 index 0000000..e73beb3 --- /dev/null +++ b/lib/src/presentation/blocs/home_bloc/home_event.dart @@ -0,0 +1,13 @@ +part of 'home_bloc.dart'; + +@freezed +class HomeEvent with _$HomeEvent { + const factory HomeEvent.loadProfile() = _LoadProfile; + const factory HomeEvent.logout() = _SendLogout; + const factory HomeEvent.goToProfile(UserData profile) = _GoToProfile; + const factory HomeEvent.goToQuota(UserData profile) = _GoToQuota; + const factory HomeEvent.goToMailQuota(UserData profile) = _GoToMailQuota; + const factory HomeEvent.goToResetPassword(UserData profile) = + _GoToResetPassword; + const factory HomeEvent.goToAboutUs(UserData profile) = _GoToAboutUs; +} diff --git a/lib/src/presentation/blocs/home_bloc/home_state.dart b/lib/src/presentation/blocs/home_bloc/home_state.dart new file mode 100644 index 0000000..2e6a2b9 --- /dev/null +++ b/lib/src/presentation/blocs/home_bloc/home_state.dart @@ -0,0 +1,28 @@ +part of 'home_bloc.dart'; + +@freezed +class HomeState with _$HomeState { + const factory HomeState.loading() = _Loading; + const factory HomeState.error(String message) = _Error; + const factory HomeState.logout() = _Logout; + const factory HomeState.profile( + UserData profile, + List items, + ) = _Profile; + const factory HomeState.quota( + UserData profile, + List items, + ) = _Quota; + const factory HomeState.mailQuota( + UserData profile, + List items, + ) = _MailQuota; + const factory HomeState.resetPassword( + UserData profile, + List items, + ) = _ResetPassword; + const factory HomeState.aboutUs( + UserData profile, + List items, + ) = _AboutUs; +} diff --git a/lib/src/presentation/blocs/login_bloc/login_bloc.dart b/lib/src/presentation/blocs/login_bloc/login_bloc.dart index 88e2ec7..c9d0adb 100644 --- a/lib/src/presentation/blocs/login_bloc/login_bloc.dart +++ b/lib/src/presentation/blocs/login_bloc/login_bloc.dart @@ -1,41 +1,39 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'login_event.dart'; part 'login_state.dart'; +part 'login_bloc.freezed.dart'; class LoginBloc extends Bloc { final AuthRepository authRepository; LoginBloc({ required this.authRepository, - }) : super(LoginAttemptInitial(error: '')); + }) : super(const LoginState.initial()); @override Stream mapEventToState(LoginEvent event) async* { - if (event is LoginAttempted) { - yield* handleLoginAttempted(event); - } + yield* event.map( + loginAttempted: loginAttemptedHandler, + ); } - Stream handleLoginAttempted(LoginAttempted event) async* { - yield LoginAttemptInProgress(); + Stream loginAttemptedHandler(_$LoginAttempted event) async* { + yield const LoginState.inProgress(); final result = await authRepository.login( - event.username, - event.password, + event.userName.trim(), + event.password.trim(), event.rememberMe, ); - if (result == null) { - yield LoginAttemptInitial( - error: Errors.DefaultError, - ); - } else if (result.error != null) { - yield LoginAttemptInitial( - error: result.error!, + if (result == null || result.error != null) { + yield LoginState.failure( + error: result?.error ?? Errors.DefaultError, ); } else { - yield LoginAttemptSuccess(); + yield const LoginState.success(); } } } diff --git a/lib/src/presentation/blocs/login_bloc/login_bloc.freezed.dart b/lib/src/presentation/blocs/login_bloc/login_bloc.freezed.dart new file mode 100644 index 0000000..1adbd1d --- /dev/null +++ b/lib/src/presentation/blocs/login_bloc/login_bloc.freezed.dart @@ -0,0 +1,747 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'login_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$LoginEventTearOff { + const _$LoginEventTearOff(); + + _$LoginAttempted loginAttempted( + {required String userName, + required String password, + required bool rememberMe}) { + return _$LoginAttempted( + userName: userName, + password: password, + rememberMe: rememberMe, + ); + } +} + +/// @nodoc +const $LoginEvent = _$LoginEventTearOff(); + +/// @nodoc +mixin _$LoginEvent { + String get userName => throw _privateConstructorUsedError; + String get password => throw _privateConstructorUsedError; + bool get rememberMe => throw _privateConstructorUsedError; + + @optionalTypeArgs + TResult when({ + required TResult Function(String userName, String password, bool rememberMe) + loginAttempted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String userName, String password, bool rememberMe)? + loginAttempted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginAttempted value) loginAttempted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginAttempted value)? loginAttempted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $LoginEventCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LoginEventCopyWith<$Res> { + factory $LoginEventCopyWith( + LoginEvent value, $Res Function(LoginEvent) then) = + _$LoginEventCopyWithImpl<$Res>; + $Res call({String userName, String password, bool rememberMe}); +} + +/// @nodoc +class _$LoginEventCopyWithImpl<$Res> implements $LoginEventCopyWith<$Res> { + _$LoginEventCopyWithImpl(this._value, this._then); + + final LoginEvent _value; + // ignore: unused_field + final $Res Function(LoginEvent) _then; + + @override + $Res call({ + Object? userName = freezed, + Object? password = freezed, + Object? rememberMe = freezed, + }) { + return _then(_value.copyWith( + userName: userName == freezed + ? _value.userName + : userName // ignore: cast_nullable_to_non_nullable + as String, + password: password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String, + rememberMe: rememberMe == freezed + ? _value.rememberMe + : rememberMe // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +abstract class _$$LoginAttemptedCopyWith<$Res> + implements $LoginEventCopyWith<$Res> { + factory _$$LoginAttemptedCopyWith( + _$LoginAttempted value, $Res Function(_$LoginAttempted) then) = + __$$LoginAttemptedCopyWithImpl<$Res>; + @override + $Res call({String userName, String password, bool rememberMe}); +} + +/// @nodoc +class __$$LoginAttemptedCopyWithImpl<$Res> + extends _$LoginEventCopyWithImpl<$Res> + implements _$$LoginAttemptedCopyWith<$Res> { + __$$LoginAttemptedCopyWithImpl( + _$LoginAttempted _value, $Res Function(_$LoginAttempted) _then) + : super(_value, (v) => _then(v as _$LoginAttempted)); + + @override + _$LoginAttempted get _value => super._value as _$LoginAttempted; + + @override + $Res call({ + Object? userName = freezed, + Object? password = freezed, + Object? rememberMe = freezed, + }) { + return _then(_$LoginAttempted( + userName: userName == freezed + ? _value.userName + : userName // ignore: cast_nullable_to_non_nullable + as String, + password: password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as String, + rememberMe: rememberMe == freezed + ? _value.rememberMe + : rememberMe // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$_$LoginAttempted implements _$LoginAttempted { + const _$_$LoginAttempted( + {required this.userName, + required this.password, + required this.rememberMe}); + + @override + final String userName; + @override + final String password; + @override + final bool rememberMe; + + @override + String toString() { + return 'LoginEvent.loginAttempted(userName: $userName, password: $password, rememberMe: $rememberMe)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$LoginAttempted && + (identical(other.userName, userName) || + const DeepCollectionEquality() + .equals(other.userName, userName)) && + (identical(other.password, password) || + const DeepCollectionEquality() + .equals(other.password, password)) && + (identical(other.rememberMe, rememberMe) || + const DeepCollectionEquality() + .equals(other.rememberMe, rememberMe))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(userName) ^ + const DeepCollectionEquality().hash(password) ^ + const DeepCollectionEquality().hash(rememberMe); + + @JsonKey(ignore: true) + @override + _$$LoginAttemptedCopyWith<_$LoginAttempted> get copyWith => + __$$LoginAttemptedCopyWithImpl<_$LoginAttempted>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String userName, String password, bool rememberMe) + loginAttempted, + }) { + return loginAttempted(userName, password, rememberMe); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String userName, String password, bool rememberMe)? + loginAttempted, + required TResult orElse(), + }) { + if (loginAttempted != null) { + return loginAttempted(userName, password, rememberMe); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginAttempted value) loginAttempted, + }) { + return loginAttempted(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginAttempted value)? loginAttempted, + required TResult orElse(), + }) { + if (loginAttempted != null) { + return loginAttempted(this); + } + return orElse(); + } +} + +abstract class _$LoginAttempted implements LoginEvent { + const factory _$LoginAttempted( + {required String userName, + required String password, + required bool rememberMe}) = _$_$LoginAttempted; + + @override + String get userName => throw _privateConstructorUsedError; + @override + String get password => throw _privateConstructorUsedError; + @override + bool get rememberMe => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$$LoginAttemptedCopyWith<_$LoginAttempted> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$LoginStateTearOff { + const _$LoginStateTearOff(); + + _$LoginInitial initial() { + return const _$LoginInitial(); + } + + _$LoginAttemptInProgress inProgress() { + return const _$LoginAttemptInProgress(); + } + + _$LoginAttemptSuccess success() { + return const _$LoginAttemptSuccess(); + } + + _$LoginAttemptFailure failure({required String error}) { + return _$LoginAttemptFailure( + error: error, + ); + } +} + +/// @nodoc +const $LoginState = _$LoginStateTearOff(); + +/// @nodoc +mixin _$LoginState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginInitial value) initial, + required TResult Function(_$LoginAttemptInProgress value) inProgress, + required TResult Function(_$LoginAttemptSuccess value) success, + required TResult Function(_$LoginAttemptFailure value) failure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginInitial value)? initial, + TResult Function(_$LoginAttemptInProgress value)? inProgress, + TResult Function(_$LoginAttemptSuccess value)? success, + TResult Function(_$LoginAttemptFailure value)? failure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LoginStateCopyWith<$Res> { + factory $LoginStateCopyWith( + LoginState value, $Res Function(LoginState) then) = + _$LoginStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$LoginStateCopyWithImpl<$Res> implements $LoginStateCopyWith<$Res> { + _$LoginStateCopyWithImpl(this._value, this._then); + + final LoginState _value; + // ignore: unused_field + final $Res Function(LoginState) _then; +} + +/// @nodoc +abstract class _$$LoginInitialCopyWith<$Res> { + factory _$$LoginInitialCopyWith( + _$LoginInitial value, $Res Function(_$LoginInitial) then) = + __$$LoginInitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoginInitialCopyWithImpl<$Res> extends _$LoginStateCopyWithImpl<$Res> + implements _$$LoginInitialCopyWith<$Res> { + __$$LoginInitialCopyWithImpl( + _$LoginInitial _value, $Res Function(_$LoginInitial) _then) + : super(_value, (v) => _then(v as _$LoginInitial)); + + @override + _$LoginInitial get _value => super._value as _$LoginInitial; +} + +/// @nodoc + +class _$_$LoginInitial implements _$LoginInitial { + const _$_$LoginInitial(); + + @override + String toString() { + return 'LoginState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$LoginInitial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginInitial value) initial, + required TResult Function(_$LoginAttemptInProgress value) inProgress, + required TResult Function(_$LoginAttemptSuccess value) success, + required TResult Function(_$LoginAttemptFailure value) failure, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginInitial value)? initial, + TResult Function(_$LoginAttemptInProgress value)? inProgress, + TResult Function(_$LoginAttemptSuccess value)? success, + TResult Function(_$LoginAttemptFailure value)? failure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _$LoginInitial implements LoginState { + const factory _$LoginInitial() = _$_$LoginInitial; +} + +/// @nodoc +abstract class _$$LoginAttemptInProgressCopyWith<$Res> { + factory _$$LoginAttemptInProgressCopyWith(_$LoginAttemptInProgress value, + $Res Function(_$LoginAttemptInProgress) then) = + __$$LoginAttemptInProgressCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoginAttemptInProgressCopyWithImpl<$Res> + extends _$LoginStateCopyWithImpl<$Res> + implements _$$LoginAttemptInProgressCopyWith<$Res> { + __$$LoginAttemptInProgressCopyWithImpl(_$LoginAttemptInProgress _value, + $Res Function(_$LoginAttemptInProgress) _then) + : super(_value, (v) => _then(v as _$LoginAttemptInProgress)); + + @override + _$LoginAttemptInProgress get _value => + super._value as _$LoginAttemptInProgress; +} + +/// @nodoc + +class _$_$LoginAttemptInProgress implements _$LoginAttemptInProgress { + const _$_$LoginAttemptInProgress(); + + @override + String toString() { + return 'LoginState.inProgress()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$LoginAttemptInProgress); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return inProgress(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginInitial value) initial, + required TResult Function(_$LoginAttemptInProgress value) inProgress, + required TResult Function(_$LoginAttemptSuccess value) success, + required TResult Function(_$LoginAttemptFailure value) failure, + }) { + return inProgress(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginInitial value)? initial, + TResult Function(_$LoginAttemptInProgress value)? inProgress, + TResult Function(_$LoginAttemptSuccess value)? success, + TResult Function(_$LoginAttemptFailure value)? failure, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(this); + } + return orElse(); + } +} + +abstract class _$LoginAttemptInProgress implements LoginState { + const factory _$LoginAttemptInProgress() = _$_$LoginAttemptInProgress; +} + +/// @nodoc +abstract class _$$LoginAttemptSuccessCopyWith<$Res> { + factory _$$LoginAttemptSuccessCopyWith(_$LoginAttemptSuccess value, + $Res Function(_$LoginAttemptSuccess) then) = + __$$LoginAttemptSuccessCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoginAttemptSuccessCopyWithImpl<$Res> + extends _$LoginStateCopyWithImpl<$Res> + implements _$$LoginAttemptSuccessCopyWith<$Res> { + __$$LoginAttemptSuccessCopyWithImpl( + _$LoginAttemptSuccess _value, $Res Function(_$LoginAttemptSuccess) _then) + : super(_value, (v) => _then(v as _$LoginAttemptSuccess)); + + @override + _$LoginAttemptSuccess get _value => super._value as _$LoginAttemptSuccess; +} + +/// @nodoc + +class _$_$LoginAttemptSuccess implements _$LoginAttemptSuccess { + const _$_$LoginAttemptSuccess(); + + @override + String toString() { + return 'LoginState.success()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$LoginAttemptSuccess); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return success(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (success != null) { + return success(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginInitial value) initial, + required TResult Function(_$LoginAttemptInProgress value) inProgress, + required TResult Function(_$LoginAttemptSuccess value) success, + required TResult Function(_$LoginAttemptFailure value) failure, + }) { + return success(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginInitial value)? initial, + TResult Function(_$LoginAttemptInProgress value)? inProgress, + TResult Function(_$LoginAttemptSuccess value)? success, + TResult Function(_$LoginAttemptFailure value)? failure, + required TResult orElse(), + }) { + if (success != null) { + return success(this); + } + return orElse(); + } +} + +abstract class _$LoginAttemptSuccess implements LoginState { + const factory _$LoginAttemptSuccess() = _$_$LoginAttemptSuccess; +} + +/// @nodoc +abstract class _$$LoginAttemptFailureCopyWith<$Res> { + factory _$$LoginAttemptFailureCopyWith(_$LoginAttemptFailure value, + $Res Function(_$LoginAttemptFailure) then) = + __$$LoginAttemptFailureCopyWithImpl<$Res>; + $Res call({String error}); +} + +/// @nodoc +class __$$LoginAttemptFailureCopyWithImpl<$Res> + extends _$LoginStateCopyWithImpl<$Res> + implements _$$LoginAttemptFailureCopyWith<$Res> { + __$$LoginAttemptFailureCopyWithImpl( + _$LoginAttemptFailure _value, $Res Function(_$LoginAttemptFailure) _then) + : super(_value, (v) => _then(v as _$LoginAttemptFailure)); + + @override + _$LoginAttemptFailure get _value => super._value as _$LoginAttemptFailure; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_$LoginAttemptFailure( + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$LoginAttemptFailure implements _$LoginAttemptFailure { + const _$_$LoginAttemptFailure({required this.error}); + + @override + final String error; + + @override + String toString() { + return 'LoginState.failure(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$LoginAttemptFailure && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$$LoginAttemptFailureCopyWith<_$LoginAttemptFailure> get copyWith => + __$$LoginAttemptFailureCopyWithImpl<_$LoginAttemptFailure>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return failure(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (failure != null) { + return failure(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$LoginInitial value) initial, + required TResult Function(_$LoginAttemptInProgress value) inProgress, + required TResult Function(_$LoginAttemptSuccess value) success, + required TResult Function(_$LoginAttemptFailure value) failure, + }) { + return failure(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$LoginInitial value)? initial, + TResult Function(_$LoginAttemptInProgress value)? inProgress, + TResult Function(_$LoginAttemptSuccess value)? success, + TResult Function(_$LoginAttemptFailure value)? failure, + required TResult orElse(), + }) { + if (failure != null) { + return failure(this); + } + return orElse(); + } +} + +abstract class _$LoginAttemptFailure implements LoginState { + const factory _$LoginAttemptFailure({required String error}) = + _$_$LoginAttemptFailure; + + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$LoginAttemptFailureCopyWith<_$LoginAttemptFailure> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/login_bloc/login_event.dart b/lib/src/presentation/blocs/login_bloc/login_event.dart index 7f5bf51..ba289a5 100644 --- a/lib/src/presentation/blocs/login_bloc/login_event.dart +++ b/lib/src/presentation/blocs/login_bloc/login_event.dart @@ -1,15 +1,10 @@ part of 'login_bloc.dart'; -abstract class LoginEvent {} - -class LoginAttempted extends LoginEvent { - final String username; - final String password; - final bool rememberMe; - - LoginAttempted({ - required this.username, - required this.password, - required this.rememberMe, - }); +@freezed +abstract class LoginEvent with _$LoginEvent { + const factory LoginEvent.loginAttempted({ + required String userName, + required String password, + required bool rememberMe, + }) = _$LoginAttempted; } diff --git a/lib/src/presentation/blocs/login_bloc/login_state.dart b/lib/src/presentation/blocs/login_bloc/login_state.dart index 08786fa..fce1e0a 100644 --- a/lib/src/presentation/blocs/login_bloc/login_state.dart +++ b/lib/src/presentation/blocs/login_bloc/login_state.dart @@ -1,13 +1,10 @@ part of 'login_bloc.dart'; -abstract class LoginState {} - -class LoginAttemptInitial extends LoginState { - final String error; - - LoginAttemptInitial({required this.error}); +@freezed +abstract class LoginState with _$LoginState { + const factory LoginState.initial() = _$LoginInitial; + const factory LoginState.inProgress() = _$LoginAttemptInProgress; + const factory LoginState.success() = _$LoginAttemptSuccess; + const factory LoginState.failure({required String error}) = + _$LoginAttemptFailure; } - -class LoginAttemptInProgress extends LoginState {} - -class LoginAttemptSuccess extends LoginState {} diff --git a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.dart b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.dart index 77f8cca..07f2e43 100644 --- a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.dart +++ b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.dart @@ -1,39 +1,37 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/data/models.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'mail_quota_event.dart'; part 'mail_quota_state.dart'; +part 'mail_quota_bloc.freezed.dart'; class MailQuotaBloc extends Bloc { final MailQuotasRepository mailQuotasRepository; MailQuotaBloc({ required this.mailQuotasRepository, - }) : super(MailQuotaInitial()); + }) : super(const MailQuotaState.initial()); @override Stream mapEventToState(MailQuotaEvent event) async* { - if (event is MailQuotaInitialized) { - yield* handleProfileInitialized(event); - } + yield* event.map( + quotaRequested: quotaRequestedHandler, + ); } - Stream handleProfileInitialized( - MailQuotaInitialized event) async* { - yield MailQuotaLoadInProgress(); + Stream quotaRequestedHandler( + _$MailQuotaRequested event) async* { + yield const MailQuotaState.loadInProgress(); final result = await mailQuotasRepository.getQuota(); - if (result == null) { - yield MailQuotaLoadedFailure( - error: Errors.DefaultError, - ); - } else if (result.error != null) { - yield MailQuotaLoadedFailure( - error: result.error, + if (result == null || result.error != null) { + yield MailQuotaState.loadFailure( + error: result?.error ?? Errors.DefaultError, ); } else { - yield MailQuotaLoadedSuccess( + yield MailQuotaState.loadSuccess( quota: result, ); } diff --git a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.freezed.dart b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.freezed.dart new file mode 100644 index 0000000..04b2098 --- /dev/null +++ b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_bloc.freezed.dart @@ -0,0 +1,674 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'mail_quota_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$MailQuotaEventTearOff { + const _$MailQuotaEventTearOff(); + + _$MailQuotaRequested quotaRequested() { + return const _$MailQuotaRequested(); + } +} + +/// @nodoc +const $MailQuotaEvent = _$MailQuotaEventTearOff(); + +/// @nodoc +mixin _$MailQuotaEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() quotaRequested, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? quotaRequested, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaRequested value) quotaRequested, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaRequested value)? quotaRequested, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MailQuotaEventCopyWith<$Res> { + factory $MailQuotaEventCopyWith( + MailQuotaEvent value, $Res Function(MailQuotaEvent) then) = + _$MailQuotaEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$MailQuotaEventCopyWithImpl<$Res> + implements $MailQuotaEventCopyWith<$Res> { + _$MailQuotaEventCopyWithImpl(this._value, this._then); + + final MailQuotaEvent _value; + // ignore: unused_field + final $Res Function(MailQuotaEvent) _then; +} + +/// @nodoc +abstract class _$$MailQuotaRequestedCopyWith<$Res> { + factory _$$MailQuotaRequestedCopyWith(_$MailQuotaRequested value, + $Res Function(_$MailQuotaRequested) then) = + __$$MailQuotaRequestedCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$MailQuotaRequestedCopyWithImpl<$Res> + extends _$MailQuotaEventCopyWithImpl<$Res> + implements _$$MailQuotaRequestedCopyWith<$Res> { + __$$MailQuotaRequestedCopyWithImpl( + _$MailQuotaRequested _value, $Res Function(_$MailQuotaRequested) _then) + : super(_value, (v) => _then(v as _$MailQuotaRequested)); + + @override + _$MailQuotaRequested get _value => super._value as _$MailQuotaRequested; +} + +/// @nodoc + +class _$_$MailQuotaRequested implements _$MailQuotaRequested { + const _$_$MailQuotaRequested(); + + @override + String toString() { + return 'MailQuotaEvent.quotaRequested()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$MailQuotaRequested); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() quotaRequested, + }) { + return quotaRequested(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? quotaRequested, + required TResult orElse(), + }) { + if (quotaRequested != null) { + return quotaRequested(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaRequested value) quotaRequested, + }) { + return quotaRequested(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaRequested value)? quotaRequested, + required TResult orElse(), + }) { + if (quotaRequested != null) { + return quotaRequested(this); + } + return orElse(); + } +} + +abstract class _$MailQuotaRequested implements MailQuotaEvent { + const factory _$MailQuotaRequested() = _$_$MailQuotaRequested; +} + +/// @nodoc +class _$MailQuotaStateTearOff { + const _$MailQuotaStateTearOff(); + + _$MailQuotaInitial initial() { + return const _$MailQuotaInitial(); + } + + _$LoadMailQuotaInProgress loadInProgress() { + return const _$LoadMailQuotaInProgress(); + } + + _$LoadMailQuotaSuccess loadSuccess({required MailQuota quota}) { + return _$LoadMailQuotaSuccess( + quota: quota, + ); + } + + _$LoadMailQuotaFailure loadFailure({required String error}) { + return _$LoadMailQuotaFailure( + error: error, + ); + } +} + +/// @nodoc +const $MailQuotaState = _$MailQuotaStateTearOff(); + +/// @nodoc +mixin _$MailQuotaState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loadInProgress, + required TResult Function(MailQuota quota) loadSuccess, + required TResult Function(String error) loadFailure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loadInProgress, + TResult Function(MailQuota quota)? loadSuccess, + TResult Function(String error)? loadFailure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaInitial value) initial, + required TResult Function(_$LoadMailQuotaInProgress value) loadInProgress, + required TResult Function(_$LoadMailQuotaSuccess value) loadSuccess, + required TResult Function(_$LoadMailQuotaFailure value) loadFailure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaInitial value)? initial, + TResult Function(_$LoadMailQuotaInProgress value)? loadInProgress, + TResult Function(_$LoadMailQuotaSuccess value)? loadSuccess, + TResult Function(_$LoadMailQuotaFailure value)? loadFailure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MailQuotaStateCopyWith<$Res> { + factory $MailQuotaStateCopyWith( + MailQuotaState value, $Res Function(MailQuotaState) then) = + _$MailQuotaStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$MailQuotaStateCopyWithImpl<$Res> + implements $MailQuotaStateCopyWith<$Res> { + _$MailQuotaStateCopyWithImpl(this._value, this._then); + + final MailQuotaState _value; + // ignore: unused_field + final $Res Function(MailQuotaState) _then; +} + +/// @nodoc +abstract class _$$MailQuotaInitialCopyWith<$Res> { + factory _$$MailQuotaInitialCopyWith( + _$MailQuotaInitial value, $Res Function(_$MailQuotaInitial) then) = + __$$MailQuotaInitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$MailQuotaInitialCopyWithImpl<$Res> + extends _$MailQuotaStateCopyWithImpl<$Res> + implements _$$MailQuotaInitialCopyWith<$Res> { + __$$MailQuotaInitialCopyWithImpl( + _$MailQuotaInitial _value, $Res Function(_$MailQuotaInitial) _then) + : super(_value, (v) => _then(v as _$MailQuotaInitial)); + + @override + _$MailQuotaInitial get _value => super._value as _$MailQuotaInitial; +} + +/// @nodoc + +class _$_$MailQuotaInitial implements _$MailQuotaInitial { + const _$_$MailQuotaInitial(); + + @override + String toString() { + return 'MailQuotaState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$MailQuotaInitial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loadInProgress, + required TResult Function(MailQuota quota) loadSuccess, + required TResult Function(String error) loadFailure, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loadInProgress, + TResult Function(MailQuota quota)? loadSuccess, + TResult Function(String error)? loadFailure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaInitial value) initial, + required TResult Function(_$LoadMailQuotaInProgress value) loadInProgress, + required TResult Function(_$LoadMailQuotaSuccess value) loadSuccess, + required TResult Function(_$LoadMailQuotaFailure value) loadFailure, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaInitial value)? initial, + TResult Function(_$LoadMailQuotaInProgress value)? loadInProgress, + TResult Function(_$LoadMailQuotaSuccess value)? loadSuccess, + TResult Function(_$LoadMailQuotaFailure value)? loadFailure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _$MailQuotaInitial implements MailQuotaState { + const factory _$MailQuotaInitial() = _$_$MailQuotaInitial; +} + +/// @nodoc +abstract class _$$LoadMailQuotaInProgressCopyWith<$Res> { + factory _$$LoadMailQuotaInProgressCopyWith(_$LoadMailQuotaInProgress value, + $Res Function(_$LoadMailQuotaInProgress) then) = + __$$LoadMailQuotaInProgressCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoadMailQuotaInProgressCopyWithImpl<$Res> + extends _$MailQuotaStateCopyWithImpl<$Res> + implements _$$LoadMailQuotaInProgressCopyWith<$Res> { + __$$LoadMailQuotaInProgressCopyWithImpl(_$LoadMailQuotaInProgress _value, + $Res Function(_$LoadMailQuotaInProgress) _then) + : super(_value, (v) => _then(v as _$LoadMailQuotaInProgress)); + + @override + _$LoadMailQuotaInProgress get _value => + super._value as _$LoadMailQuotaInProgress; +} + +/// @nodoc + +class _$_$LoadMailQuotaInProgress implements _$LoadMailQuotaInProgress { + const _$_$LoadMailQuotaInProgress(); + + @override + String toString() { + return 'MailQuotaState.loadInProgress()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$LoadMailQuotaInProgress); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loadInProgress, + required TResult Function(MailQuota quota) loadSuccess, + required TResult Function(String error) loadFailure, + }) { + return loadInProgress(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loadInProgress, + TResult Function(MailQuota quota)? loadSuccess, + TResult Function(String error)? loadFailure, + required TResult orElse(), + }) { + if (loadInProgress != null) { + return loadInProgress(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaInitial value) initial, + required TResult Function(_$LoadMailQuotaInProgress value) loadInProgress, + required TResult Function(_$LoadMailQuotaSuccess value) loadSuccess, + required TResult Function(_$LoadMailQuotaFailure value) loadFailure, + }) { + return loadInProgress(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaInitial value)? initial, + TResult Function(_$LoadMailQuotaInProgress value)? loadInProgress, + TResult Function(_$LoadMailQuotaSuccess value)? loadSuccess, + TResult Function(_$LoadMailQuotaFailure value)? loadFailure, + required TResult orElse(), + }) { + if (loadInProgress != null) { + return loadInProgress(this); + } + return orElse(); + } +} + +abstract class _$LoadMailQuotaInProgress implements MailQuotaState { + const factory _$LoadMailQuotaInProgress() = _$_$LoadMailQuotaInProgress; +} + +/// @nodoc +abstract class _$$LoadMailQuotaSuccessCopyWith<$Res> { + factory _$$LoadMailQuotaSuccessCopyWith(_$LoadMailQuotaSuccess value, + $Res Function(_$LoadMailQuotaSuccess) then) = + __$$LoadMailQuotaSuccessCopyWithImpl<$Res>; + $Res call({MailQuota quota}); +} + +/// @nodoc +class __$$LoadMailQuotaSuccessCopyWithImpl<$Res> + extends _$MailQuotaStateCopyWithImpl<$Res> + implements _$$LoadMailQuotaSuccessCopyWith<$Res> { + __$$LoadMailQuotaSuccessCopyWithImpl(_$LoadMailQuotaSuccess _value, + $Res Function(_$LoadMailQuotaSuccess) _then) + : super(_value, (v) => _then(v as _$LoadMailQuotaSuccess)); + + @override + _$LoadMailQuotaSuccess get _value => super._value as _$LoadMailQuotaSuccess; + + @override + $Res call({ + Object? quota = freezed, + }) { + return _then(_$LoadMailQuotaSuccess( + quota: quota == freezed + ? _value.quota + : quota // ignore: cast_nullable_to_non_nullable + as MailQuota, + )); + } +} + +/// @nodoc + +class _$_$LoadMailQuotaSuccess implements _$LoadMailQuotaSuccess { + const _$_$LoadMailQuotaSuccess({required this.quota}); + + @override + final MailQuota quota; + + @override + String toString() { + return 'MailQuotaState.loadSuccess(quota: $quota)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$LoadMailQuotaSuccess && + (identical(other.quota, quota) || + const DeepCollectionEquality().equals(other.quota, quota))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(quota); + + @JsonKey(ignore: true) + @override + _$$LoadMailQuotaSuccessCopyWith<_$LoadMailQuotaSuccess> get copyWith => + __$$LoadMailQuotaSuccessCopyWithImpl<_$LoadMailQuotaSuccess>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loadInProgress, + required TResult Function(MailQuota quota) loadSuccess, + required TResult Function(String error) loadFailure, + }) { + return loadSuccess(quota); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loadInProgress, + TResult Function(MailQuota quota)? loadSuccess, + TResult Function(String error)? loadFailure, + required TResult orElse(), + }) { + if (loadSuccess != null) { + return loadSuccess(quota); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaInitial value) initial, + required TResult Function(_$LoadMailQuotaInProgress value) loadInProgress, + required TResult Function(_$LoadMailQuotaSuccess value) loadSuccess, + required TResult Function(_$LoadMailQuotaFailure value) loadFailure, + }) { + return loadSuccess(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaInitial value)? initial, + TResult Function(_$LoadMailQuotaInProgress value)? loadInProgress, + TResult Function(_$LoadMailQuotaSuccess value)? loadSuccess, + TResult Function(_$LoadMailQuotaFailure value)? loadFailure, + required TResult orElse(), + }) { + if (loadSuccess != null) { + return loadSuccess(this); + } + return orElse(); + } +} + +abstract class _$LoadMailQuotaSuccess implements MailQuotaState { + const factory _$LoadMailQuotaSuccess({required MailQuota quota}) = + _$_$LoadMailQuotaSuccess; + + MailQuota get quota => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$LoadMailQuotaSuccessCopyWith<_$LoadMailQuotaSuccess> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$LoadMailQuotaFailureCopyWith<$Res> { + factory _$$LoadMailQuotaFailureCopyWith(_$LoadMailQuotaFailure value, + $Res Function(_$LoadMailQuotaFailure) then) = + __$$LoadMailQuotaFailureCopyWithImpl<$Res>; + $Res call({String error}); +} + +/// @nodoc +class __$$LoadMailQuotaFailureCopyWithImpl<$Res> + extends _$MailQuotaStateCopyWithImpl<$Res> + implements _$$LoadMailQuotaFailureCopyWith<$Res> { + __$$LoadMailQuotaFailureCopyWithImpl(_$LoadMailQuotaFailure _value, + $Res Function(_$LoadMailQuotaFailure) _then) + : super(_value, (v) => _then(v as _$LoadMailQuotaFailure)); + + @override + _$LoadMailQuotaFailure get _value => super._value as _$LoadMailQuotaFailure; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_$LoadMailQuotaFailure( + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$LoadMailQuotaFailure implements _$LoadMailQuotaFailure { + const _$_$LoadMailQuotaFailure({required this.error}); + + @override + final String error; + + @override + String toString() { + return 'MailQuotaState.loadFailure(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$LoadMailQuotaFailure && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$$LoadMailQuotaFailureCopyWith<_$LoadMailQuotaFailure> get copyWith => + __$$LoadMailQuotaFailureCopyWithImpl<_$LoadMailQuotaFailure>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loadInProgress, + required TResult Function(MailQuota quota) loadSuccess, + required TResult Function(String error) loadFailure, + }) { + return loadFailure(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loadInProgress, + TResult Function(MailQuota quota)? loadSuccess, + TResult Function(String error)? loadFailure, + required TResult orElse(), + }) { + if (loadFailure != null) { + return loadFailure(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$MailQuotaInitial value) initial, + required TResult Function(_$LoadMailQuotaInProgress value) loadInProgress, + required TResult Function(_$LoadMailQuotaSuccess value) loadSuccess, + required TResult Function(_$LoadMailQuotaFailure value) loadFailure, + }) { + return loadFailure(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$MailQuotaInitial value)? initial, + TResult Function(_$LoadMailQuotaInProgress value)? loadInProgress, + TResult Function(_$LoadMailQuotaSuccess value)? loadSuccess, + TResult Function(_$LoadMailQuotaFailure value)? loadFailure, + required TResult orElse(), + }) { + if (loadFailure != null) { + return loadFailure(this); + } + return orElse(); + } +} + +abstract class _$LoadMailQuotaFailure implements MailQuotaState { + const factory _$LoadMailQuotaFailure({required String error}) = + _$_$LoadMailQuotaFailure; + + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$LoadMailQuotaFailureCopyWith<_$LoadMailQuotaFailure> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_event.dart b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_event.dart index 8b9313c..dfcb835 100644 --- a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_event.dart +++ b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_event.dart @@ -1,5 +1,6 @@ part of 'mail_quota_bloc.dart'; -abstract class MailQuotaEvent {} - -class MailQuotaInitialized extends MailQuotaEvent {} +@freezed +abstract class MailQuotaEvent with _$MailQuotaEvent { + const factory MailQuotaEvent.quotaRequested() = _$MailQuotaRequested; +} diff --git a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_state.dart b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_state.dart index c47a9ea..3f8c913 100644 --- a/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_state.dart +++ b/lib/src/presentation/blocs/mail_quota_bloc/mail_quota_state.dart @@ -1,23 +1,11 @@ part of 'mail_quota_bloc.dart'; -abstract class MailQuotaState {} - -class MailQuotaInitial extends MailQuotaState {} - -class MailQuotaLoadInProgress extends MailQuotaState {} - -class MailQuotaLoadedSuccess extends MailQuotaState { - final MailQuota? quota; - - MailQuotaLoadedSuccess({ - this.quota, - }); -} - -class MailQuotaLoadedFailure extends MailQuotaState { - final String? error; - - MailQuotaLoadedFailure({ - this.error, - }); +@freezed +abstract class MailQuotaState with _$MailQuotaState { + const factory MailQuotaState.initial() = _$MailQuotaInitial; + const factory MailQuotaState.loadInProgress() = _$LoadMailQuotaInProgress; + const factory MailQuotaState.loadSuccess({required MailQuota quota}) = + _$LoadMailQuotaSuccess; + const factory MailQuotaState.loadFailure({required String error}) = + _$LoadMailQuotaFailure; } diff --git a/lib/src/presentation/blocs/profile_bloc/profile_bloc.dart b/lib/src/presentation/blocs/profile_bloc/profile_bloc.dart index bac8cbd..1efae01 100644 --- a/lib/src/presentation/blocs/profile_bloc/profile_bloc.dart +++ b/lib/src/presentation/blocs/profile_bloc/profile_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/data/models.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'profile_event.dart'; part 'profile_state.dart'; diff --git a/lib/src/presentation/blocs/quota_bloc/quota_bloc.dart b/lib/src/presentation/blocs/quota_bloc/quota_bloc.dart index 4ec5bf5..6520413 100644 --- a/lib/src/presentation/blocs/quota_bloc/quota_bloc.dart +++ b/lib/src/presentation/blocs/quota_bloc/quota_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/data/models.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'quota_event.dart'; part 'quota_state.dart'; diff --git a/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.dart b/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.dart index 16da32c..c363291 100644 --- a/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.dart +++ b/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.dart @@ -2,11 +2,12 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; -import 'package:gestionuh/src/data/models.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:meta/meta.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +part 'recover_password_bloc.freezed.dart'; part 'recover_password_event.dart'; part 'recover_password_state.dart'; @@ -15,95 +16,85 @@ class RecoverPasswordBloc final RecoverPasswordRepository recoverPasswordRepository; RecoverPasswordBloc({required this.recoverPasswordRepository}) - : super(RecoverPasswordInitial(ci: TextEditingController())); + : super(RecoverPasswordState.initial(TextEditingController())); @override Stream mapEventToState( RecoverPasswordEvent event, ) async* { - if (event is RecoverPasswordCISubmit) { - yield* handleCISubmit(event); - } - if (event is RecoverPasswordFinalSubmit) { - yield* handleFinalSubmit(event); - } + yield* event.when( + ciSubmit: handleCISubmit, + finalSubmit: handleFinalSubmit, + ); } - Stream handleCISubmit( - RecoverPasswordCISubmit event, - ) async* { - yield RecoverPasswordCILoading(ci: event.state.ci); + Stream handleCISubmit(TextEditingController ci) async* { + yield RecoverPasswordState.ciLoading(ci); final result = await recoverPasswordRepository.getUserSecurityQuestions( - event.state.ci.text.trim(), + ci.text.trim(), ); if (result == null) { - yield RecoverPasswordCIError( - ci: event.state.ci, - error: Errors.DefaultError, - ); + yield RecoverPasswordState.ciError(ci, Errors.DefaultError); } else if (result.error != null) { - yield RecoverPasswordCIError( - ci: event.state.ci, - error: result.error!, - ); + yield RecoverPasswordState.ciError(ci, result.error!); } else if (result.questions == null) { - yield RecoverPasswordCIError( - ci: event.state.ci, - error: Errors.DefaultError, - ); + yield RecoverPasswordState.ciError(ci, Errors.DefaultError); } else { - yield RecoverPasswordQuestions( - ci: event.state.ci.text.trim(), - questions: result.questions!, - answers: result.questions!.map((_) => TextEditingController()).toList(), - password: TextEditingController(), + yield RecoverPasswordState.questions( + ci.text.trim(), + result.questions!, + result.questions!.map((_) => TextEditingController()).toList(), + TextEditingController(), ); } } Stream handleFinalSubmit( - RecoverPasswordFinalSubmit event, + String ci, + List questions, + List answers, + TextEditingController password, ) async* { - yield RecoverPasswordQuestionsLoading( - ci: event.state.ci, - questions: event.state.questions, - answers: event.state.answers, - password: event.state.password, + yield RecoverPasswordState.questionsLoading( + ci, + questions, + answers, + password, ); final result = await recoverPasswordRepository.passwordRecovery( PasswordResetData( - ci: event.state.ci, - questions: event.state.questions, - answers: event.state.answers.map((e) => e.text.trim()).toList(), - newPassword: event.state.password.text.trim(), + ci: ci, + questions: questions, + answers: answers.map((e) => e.text.trim()).toList(), + newPassword: password.text.trim(), ), ); if (result == null) { - yield RecoverPasswordQuestionsError( - ci: event.state.ci, - questions: event.state.questions, - answers: event.state.answers, - password: event.state.password, - error: Errors.DefaultError, + yield RecoverPasswordState.questionsError( + ci, + questions, + answers, + password, + Errors.DefaultError, ); } else if (result.error != null) { - yield RecoverPasswordQuestionsError( - ci: event.state.ci, - questions: event.state.questions, - answers: event.state.answers, - password: event.state.password, - error: result.error!, + yield RecoverPasswordState.questionsError( + ci, + questions, + answers, + password, + result.error!, ); } else if (result.userId == null) { - yield RecoverPasswordQuestionsError( - ci: event.state.ci, - questions: event.state.questions, - answers: event.state.answers, - password: event.state.password, - error: Errors.DefaultError, + yield RecoverPasswordState.questionsError( + ci, + questions, + answers, + password, + Errors.DefaultError, ); } else { - yield RecoverPasswordSuccess(userId: result.userId!); + yield RecoverPasswordState.success(result.userId!); } } } diff --git a/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.freezed.dart b/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.freezed.dart new file mode 100644 index 0000000..1d7b5b3 --- /dev/null +++ b/lib/src/presentation/blocs/recover_password_bloc/recover_password_bloc.freezed.dart @@ -0,0 +1,1829 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'recover_password_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$RecoverPasswordEventTearOff { + const _$RecoverPasswordEventTearOff(); + + _CISubmit ciSubmit(TextEditingController ci) { + return _CISubmit( + ci, + ); + } + + _FinalSubmit finalSubmit(String ci, List questions, + List answers, TextEditingController password) { + return _FinalSubmit( + ci, + questions, + answers, + password, + ); + } +} + +/// @nodoc +const $RecoverPasswordEvent = _$RecoverPasswordEventTearOff(); + +/// @nodoc +mixin _$RecoverPasswordEvent { + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) ciSubmit, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + finalSubmit, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? ciSubmit, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + finalSubmit, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_CISubmit value) ciSubmit, + required TResult Function(_FinalSubmit value) finalSubmit, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_CISubmit value)? ciSubmit, + TResult Function(_FinalSubmit value)? finalSubmit, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RecoverPasswordEventCopyWith<$Res> { + factory $RecoverPasswordEventCopyWith(RecoverPasswordEvent value, + $Res Function(RecoverPasswordEvent) then) = + _$RecoverPasswordEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$RecoverPasswordEventCopyWithImpl<$Res> + implements $RecoverPasswordEventCopyWith<$Res> { + _$RecoverPasswordEventCopyWithImpl(this._value, this._then); + + final RecoverPasswordEvent _value; + // ignore: unused_field + final $Res Function(RecoverPasswordEvent) _then; +} + +/// @nodoc +abstract class _$CISubmitCopyWith<$Res> { + factory _$CISubmitCopyWith(_CISubmit value, $Res Function(_CISubmit) then) = + __$CISubmitCopyWithImpl<$Res>; + $Res call({TextEditingController ci}); +} + +/// @nodoc +class __$CISubmitCopyWithImpl<$Res> + extends _$RecoverPasswordEventCopyWithImpl<$Res> + implements _$CISubmitCopyWith<$Res> { + __$CISubmitCopyWithImpl(_CISubmit _value, $Res Function(_CISubmit) _then) + : super(_value, (v) => _then(v as _CISubmit)); + + @override + _CISubmit get _value => super._value as _CISubmit; + + @override + $Res call({ + Object? ci = freezed, + }) { + return _then(_CISubmit( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_CISubmit implements _CISubmit { + const _$_CISubmit(this.ci); + + @override + final TextEditingController ci; + + @override + String toString() { + return 'RecoverPasswordEvent.ciSubmit(ci: $ci)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _CISubmit && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(ci); + + @JsonKey(ignore: true) + @override + _$CISubmitCopyWith<_CISubmit> get copyWith => + __$CISubmitCopyWithImpl<_CISubmit>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) ciSubmit, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + finalSubmit, + }) { + return ciSubmit(ci); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? ciSubmit, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + finalSubmit, + required TResult orElse(), + }) { + if (ciSubmit != null) { + return ciSubmit(ci); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_CISubmit value) ciSubmit, + required TResult Function(_FinalSubmit value) finalSubmit, + }) { + return ciSubmit(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_CISubmit value)? ciSubmit, + TResult Function(_FinalSubmit value)? finalSubmit, + required TResult orElse(), + }) { + if (ciSubmit != null) { + return ciSubmit(this); + } + return orElse(); + } +} + +abstract class _CISubmit implements RecoverPasswordEvent { + const factory _CISubmit(TextEditingController ci) = _$_CISubmit; + + TextEditingController get ci => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$CISubmitCopyWith<_CISubmit> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$FinalSubmitCopyWith<$Res> { + factory _$FinalSubmitCopyWith( + _FinalSubmit value, $Res Function(_FinalSubmit) then) = + __$FinalSubmitCopyWithImpl<$Res>; + $Res call( + {String ci, + List questions, + List answers, + TextEditingController password}); +} + +/// @nodoc +class __$FinalSubmitCopyWithImpl<$Res> + extends _$RecoverPasswordEventCopyWithImpl<$Res> + implements _$FinalSubmitCopyWith<$Res> { + __$FinalSubmitCopyWithImpl( + _FinalSubmit _value, $Res Function(_FinalSubmit) _then) + : super(_value, (v) => _then(v as _FinalSubmit)); + + @override + _FinalSubmit get _value => super._value as _FinalSubmit; + + @override + $Res call({ + Object? ci = freezed, + Object? questions = freezed, + Object? answers = freezed, + Object? password = freezed, + }) { + return _then(_FinalSubmit( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as String, + questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + answers == freezed + ? _value.answers + : answers // ignore: cast_nullable_to_non_nullable + as List, + password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_FinalSubmit implements _FinalSubmit { + const _$_FinalSubmit(this.ci, this.questions, this.answers, this.password); + + @override + final String ci; + @override + final List questions; + @override + final List answers; + @override + final TextEditingController password; + + @override + String toString() { + return 'RecoverPasswordEvent.finalSubmit(ci: $ci, questions: $questions, answers: $answers, password: $password)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _FinalSubmit && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions)) && + (identical(other.answers, answers) || + const DeepCollectionEquality() + .equals(other.answers, answers)) && + (identical(other.password, password) || + const DeepCollectionEquality() + .equals(other.password, password))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(questions) ^ + const DeepCollectionEquality().hash(answers) ^ + const DeepCollectionEquality().hash(password); + + @JsonKey(ignore: true) + @override + _$FinalSubmitCopyWith<_FinalSubmit> get copyWith => + __$FinalSubmitCopyWithImpl<_FinalSubmit>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) ciSubmit, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + finalSubmit, + }) { + return finalSubmit(ci, questions, answers, password); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? ciSubmit, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + finalSubmit, + required TResult orElse(), + }) { + if (finalSubmit != null) { + return finalSubmit(ci, questions, answers, password); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_CISubmit value) ciSubmit, + required TResult Function(_FinalSubmit value) finalSubmit, + }) { + return finalSubmit(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_CISubmit value)? ciSubmit, + TResult Function(_FinalSubmit value)? finalSubmit, + required TResult orElse(), + }) { + if (finalSubmit != null) { + return finalSubmit(this); + } + return orElse(); + } +} + +abstract class _FinalSubmit implements RecoverPasswordEvent { + const factory _FinalSubmit( + String ci, + List questions, + List answers, + TextEditingController password) = _$_FinalSubmit; + + String get ci => throw _privateConstructorUsedError; + List get questions => throw _privateConstructorUsedError; + List get answers => throw _privateConstructorUsedError; + TextEditingController get password => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$FinalSubmitCopyWith<_FinalSubmit> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$RecoverPasswordStateTearOff { + const _$RecoverPasswordStateTearOff(); + + _Initial initial(TextEditingController ci) { + return _Initial( + ci, + ); + } + + _CILoading ciLoading(TextEditingController ci) { + return _CILoading( + ci, + ); + } + + _CIError ciError(TextEditingController ci, String error) { + return _CIError( + ci, + error, + ); + } + + _Questions questions(String ci, List questions, + List answers, TextEditingController password) { + return _Questions( + ci, + questions, + answers, + password, + ); + } + + _QuestionsLoading questionsLoading(String ci, List questions, + List answers, TextEditingController password) { + return _QuestionsLoading( + ci, + questions, + answers, + password, + ); + } + + _QuestionsError questionsError( + String ci, + List questions, + List answers, + TextEditingController password, + String error) { + return _QuestionsError( + ci, + questions, + answers, + password, + error, + ); + } + + _Success success(String userId) { + return _Success( + userId, + ); + } +} + +/// @nodoc +const $RecoverPasswordState = _$RecoverPasswordStateTearOff(); + +/// @nodoc +mixin _$RecoverPasswordState { + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RecoverPasswordStateCopyWith<$Res> { + factory $RecoverPasswordStateCopyWith(RecoverPasswordState value, + $Res Function(RecoverPasswordState) then) = + _$RecoverPasswordStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$RecoverPasswordStateCopyWithImpl<$Res> + implements $RecoverPasswordStateCopyWith<$Res> { + _$RecoverPasswordStateCopyWithImpl(this._value, this._then); + + final RecoverPasswordState _value; + // ignore: unused_field + final $Res Function(RecoverPasswordState) _then; +} + +/// @nodoc +abstract class _$InitialCopyWith<$Res> { + factory _$InitialCopyWith(_Initial value, $Res Function(_Initial) then) = + __$InitialCopyWithImpl<$Res>; + $Res call({TextEditingController ci}); +} + +/// @nodoc +class __$InitialCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$InitialCopyWith<$Res> { + __$InitialCopyWithImpl(_Initial _value, $Res Function(_Initial) _then) + : super(_value, (v) => _then(v as _Initial)); + + @override + _Initial get _value => super._value as _Initial; + + @override + $Res call({ + Object? ci = freezed, + }) { + return _then(_Initial( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_Initial implements _Initial { + const _$_Initial(this.ci); + + @override + final TextEditingController ci; + + @override + String toString() { + return 'RecoverPasswordState.initial(ci: $ci)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Initial && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(ci); + + @JsonKey(ignore: true) + @override + _$InitialCopyWith<_Initial> get copyWith => + __$InitialCopyWithImpl<_Initial>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return initial(ci); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (initial != null) { + return initial(ci); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements RecoverPasswordState { + const factory _Initial(TextEditingController ci) = _$_Initial; + + TextEditingController get ci => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$InitialCopyWith<_Initial> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$CILoadingCopyWith<$Res> { + factory _$CILoadingCopyWith( + _CILoading value, $Res Function(_CILoading) then) = + __$CILoadingCopyWithImpl<$Res>; + $Res call({TextEditingController ci}); +} + +/// @nodoc +class __$CILoadingCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$CILoadingCopyWith<$Res> { + __$CILoadingCopyWithImpl(_CILoading _value, $Res Function(_CILoading) _then) + : super(_value, (v) => _then(v as _CILoading)); + + @override + _CILoading get _value => super._value as _CILoading; + + @override + $Res call({ + Object? ci = freezed, + }) { + return _then(_CILoading( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_CILoading implements _CILoading { + const _$_CILoading(this.ci); + + @override + final TextEditingController ci; + + @override + String toString() { + return 'RecoverPasswordState.ciLoading(ci: $ci)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _CILoading && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(ci); + + @JsonKey(ignore: true) + @override + _$CILoadingCopyWith<_CILoading> get copyWith => + __$CILoadingCopyWithImpl<_CILoading>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return ciLoading(ci); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (ciLoading != null) { + return ciLoading(ci); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return ciLoading(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (ciLoading != null) { + return ciLoading(this); + } + return orElse(); + } +} + +abstract class _CILoading implements RecoverPasswordState { + const factory _CILoading(TextEditingController ci) = _$_CILoading; + + TextEditingController get ci => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$CILoadingCopyWith<_CILoading> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$CIErrorCopyWith<$Res> { + factory _$CIErrorCopyWith(_CIError value, $Res Function(_CIError) then) = + __$CIErrorCopyWithImpl<$Res>; + $Res call({TextEditingController ci, String error}); +} + +/// @nodoc +class __$CIErrorCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$CIErrorCopyWith<$Res> { + __$CIErrorCopyWithImpl(_CIError _value, $Res Function(_CIError) _then) + : super(_value, (v) => _then(v as _CIError)); + + @override + _CIError get _value => super._value as _CIError; + + @override + $Res call({ + Object? ci = freezed, + Object? error = freezed, + }) { + return _then(_CIError( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as TextEditingController, + error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_CIError implements _CIError { + const _$_CIError(this.ci, this.error); + + @override + final TextEditingController ci; + @override + final String error; + + @override + String toString() { + return 'RecoverPasswordState.ciError(ci: $ci, error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _CIError && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$CIErrorCopyWith<_CIError> get copyWith => + __$CIErrorCopyWithImpl<_CIError>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return ciError(ci, error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (ciError != null) { + return ciError(ci, error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return ciError(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (ciError != null) { + return ciError(this); + } + return orElse(); + } +} + +abstract class _CIError implements RecoverPasswordState { + const factory _CIError(TextEditingController ci, String error) = _$_CIError; + + TextEditingController get ci => throw _privateConstructorUsedError; + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$CIErrorCopyWith<_CIError> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$QuestionsCopyWith<$Res> { + factory _$QuestionsCopyWith( + _Questions value, $Res Function(_Questions) then) = + __$QuestionsCopyWithImpl<$Res>; + $Res call( + {String ci, + List questions, + List answers, + TextEditingController password}); +} + +/// @nodoc +class __$QuestionsCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$QuestionsCopyWith<$Res> { + __$QuestionsCopyWithImpl(_Questions _value, $Res Function(_Questions) _then) + : super(_value, (v) => _then(v as _Questions)); + + @override + _Questions get _value => super._value as _Questions; + + @override + $Res call({ + Object? ci = freezed, + Object? questions = freezed, + Object? answers = freezed, + Object? password = freezed, + }) { + return _then(_Questions( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as String, + questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + answers == freezed + ? _value.answers + : answers // ignore: cast_nullable_to_non_nullable + as List, + password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_Questions implements _Questions { + const _$_Questions(this.ci, this.questions, this.answers, this.password); + + @override + final String ci; + @override + final List questions; + @override + final List answers; + @override + final TextEditingController password; + + @override + String toString() { + return 'RecoverPasswordState.questions(ci: $ci, questions: $questions, answers: $answers, password: $password)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Questions && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions)) && + (identical(other.answers, answers) || + const DeepCollectionEquality() + .equals(other.answers, answers)) && + (identical(other.password, password) || + const DeepCollectionEquality() + .equals(other.password, password))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(questions) ^ + const DeepCollectionEquality().hash(answers) ^ + const DeepCollectionEquality().hash(password); + + @JsonKey(ignore: true) + @override + _$QuestionsCopyWith<_Questions> get copyWith => + __$QuestionsCopyWithImpl<_Questions>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return questions(ci, this.questions, answers, password); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (questions != null) { + return questions(ci, this.questions, answers, password); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return questions(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (questions != null) { + return questions(this); + } + return orElse(); + } +} + +abstract class _Questions implements RecoverPasswordState { + const factory _Questions( + String ci, + List questions, + List answers, + TextEditingController password) = _$_Questions; + + String get ci => throw _privateConstructorUsedError; + List get questions => throw _privateConstructorUsedError; + List get answers => throw _privateConstructorUsedError; + TextEditingController get password => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$QuestionsCopyWith<_Questions> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$QuestionsLoadingCopyWith<$Res> { + factory _$QuestionsLoadingCopyWith( + _QuestionsLoading value, $Res Function(_QuestionsLoading) then) = + __$QuestionsLoadingCopyWithImpl<$Res>; + $Res call( + {String ci, + List questions, + List answers, + TextEditingController password}); +} + +/// @nodoc +class __$QuestionsLoadingCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$QuestionsLoadingCopyWith<$Res> { + __$QuestionsLoadingCopyWithImpl( + _QuestionsLoading _value, $Res Function(_QuestionsLoading) _then) + : super(_value, (v) => _then(v as _QuestionsLoading)); + + @override + _QuestionsLoading get _value => super._value as _QuestionsLoading; + + @override + $Res call({ + Object? ci = freezed, + Object? questions = freezed, + Object? answers = freezed, + Object? password = freezed, + }) { + return _then(_QuestionsLoading( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as String, + questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + answers == freezed + ? _value.answers + : answers // ignore: cast_nullable_to_non_nullable + as List, + password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as TextEditingController, + )); + } +} + +/// @nodoc + +class _$_QuestionsLoading implements _QuestionsLoading { + const _$_QuestionsLoading( + this.ci, this.questions, this.answers, this.password); + + @override + final String ci; + @override + final List questions; + @override + final List answers; + @override + final TextEditingController password; + + @override + String toString() { + return 'RecoverPasswordState.questionsLoading(ci: $ci, questions: $questions, answers: $answers, password: $password)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _QuestionsLoading && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions)) && + (identical(other.answers, answers) || + const DeepCollectionEquality() + .equals(other.answers, answers)) && + (identical(other.password, password) || + const DeepCollectionEquality() + .equals(other.password, password))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(questions) ^ + const DeepCollectionEquality().hash(answers) ^ + const DeepCollectionEquality().hash(password); + + @JsonKey(ignore: true) + @override + _$QuestionsLoadingCopyWith<_QuestionsLoading> get copyWith => + __$QuestionsLoadingCopyWithImpl<_QuestionsLoading>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return questionsLoading(ci, this.questions, answers, password); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (questionsLoading != null) { + return questionsLoading(ci, this.questions, answers, password); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return questionsLoading(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (questionsLoading != null) { + return questionsLoading(this); + } + return orElse(); + } +} + +abstract class _QuestionsLoading implements RecoverPasswordState { + const factory _QuestionsLoading( + String ci, + List questions, + List answers, + TextEditingController password) = _$_QuestionsLoading; + + String get ci => throw _privateConstructorUsedError; + List get questions => throw _privateConstructorUsedError; + List get answers => throw _privateConstructorUsedError; + TextEditingController get password => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$QuestionsLoadingCopyWith<_QuestionsLoading> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$QuestionsErrorCopyWith<$Res> { + factory _$QuestionsErrorCopyWith( + _QuestionsError value, $Res Function(_QuestionsError) then) = + __$QuestionsErrorCopyWithImpl<$Res>; + $Res call( + {String ci, + List questions, + List answers, + TextEditingController password, + String error}); +} + +/// @nodoc +class __$QuestionsErrorCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$QuestionsErrorCopyWith<$Res> { + __$QuestionsErrorCopyWithImpl( + _QuestionsError _value, $Res Function(_QuestionsError) _then) + : super(_value, (v) => _then(v as _QuestionsError)); + + @override + _QuestionsError get _value => super._value as _QuestionsError; + + @override + $Res call({ + Object? ci = freezed, + Object? questions = freezed, + Object? answers = freezed, + Object? password = freezed, + Object? error = freezed, + }) { + return _then(_QuestionsError( + ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as String, + questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + answers == freezed + ? _value.answers + : answers // ignore: cast_nullable_to_non_nullable + as List, + password == freezed + ? _value.password + : password // ignore: cast_nullable_to_non_nullable + as TextEditingController, + error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_QuestionsError implements _QuestionsError { + const _$_QuestionsError( + this.ci, this.questions, this.answers, this.password, this.error); + + @override + final String ci; + @override + final List questions; + @override + final List answers; + @override + final TextEditingController password; + @override + final String error; + + @override + String toString() { + return 'RecoverPasswordState.questionsError(ci: $ci, questions: $questions, answers: $answers, password: $password, error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _QuestionsError && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions)) && + (identical(other.answers, answers) || + const DeepCollectionEquality() + .equals(other.answers, answers)) && + (identical(other.password, password) || + const DeepCollectionEquality() + .equals(other.password, password)) && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(questions) ^ + const DeepCollectionEquality().hash(answers) ^ + const DeepCollectionEquality().hash(password) ^ + const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$QuestionsErrorCopyWith<_QuestionsError> get copyWith => + __$QuestionsErrorCopyWithImpl<_QuestionsError>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return questionsError(ci, this.questions, answers, password, error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (questionsError != null) { + return questionsError(ci, this.questions, answers, password, error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return questionsError(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (questionsError != null) { + return questionsError(this); + } + return orElse(); + } +} + +abstract class _QuestionsError implements RecoverPasswordState { + const factory _QuestionsError( + String ci, + List questions, + List answers, + TextEditingController password, + String error) = _$_QuestionsError; + + String get ci => throw _privateConstructorUsedError; + List get questions => throw _privateConstructorUsedError; + List get answers => throw _privateConstructorUsedError; + TextEditingController get password => throw _privateConstructorUsedError; + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$QuestionsErrorCopyWith<_QuestionsError> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$SuccessCopyWith<$Res> { + factory _$SuccessCopyWith(_Success value, $Res Function(_Success) then) = + __$SuccessCopyWithImpl<$Res>; + $Res call({String userId}); +} + +/// @nodoc +class __$SuccessCopyWithImpl<$Res> + extends _$RecoverPasswordStateCopyWithImpl<$Res> + implements _$SuccessCopyWith<$Res> { + __$SuccessCopyWithImpl(_Success _value, $Res Function(_Success) _then) + : super(_value, (v) => _then(v as _Success)); + + @override + _Success get _value => super._value as _Success; + + @override + $Res call({ + Object? userId = freezed, + }) { + return _then(_Success( + userId == freezed + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_Success implements _Success { + const _$_Success(this.userId); + + @override + final String userId; + + @override + String toString() { + return 'RecoverPasswordState.success(userId: $userId)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Success && + (identical(other.userId, userId) || + const DeepCollectionEquality().equals(other.userId, userId))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(userId); + + @JsonKey(ignore: true) + @override + _$SuccessCopyWith<_Success> get copyWith => + __$SuccessCopyWithImpl<_Success>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(TextEditingController ci) initial, + required TResult Function(TextEditingController ci) ciLoading, + required TResult Function(TextEditingController ci, String error) ciError, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questions, + required TResult Function(String ci, List questions, + List answers, TextEditingController password) + questionsLoading, + required TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error) + questionsError, + required TResult Function(String userId) success, + }) { + return success(userId); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(TextEditingController ci)? initial, + TResult Function(TextEditingController ci)? ciLoading, + TResult Function(TextEditingController ci, String error)? ciError, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questions, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password)? + questionsLoading, + TResult Function( + String ci, + List questions, + List answers, + TextEditingController password, + String error)? + questionsError, + TResult Function(String userId)? success, + required TResult orElse(), + }) { + if (success != null) { + return success(userId); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CILoading value) ciLoading, + required TResult Function(_CIError value) ciError, + required TResult Function(_Questions value) questions, + required TResult Function(_QuestionsLoading value) questionsLoading, + required TResult Function(_QuestionsError value) questionsError, + required TResult Function(_Success value) success, + }) { + return success(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CILoading value)? ciLoading, + TResult Function(_CIError value)? ciError, + TResult Function(_Questions value)? questions, + TResult Function(_QuestionsLoading value)? questionsLoading, + TResult Function(_QuestionsError value)? questionsError, + TResult Function(_Success value)? success, + required TResult orElse(), + }) { + if (success != null) { + return success(this); + } + return orElse(); + } +} + +abstract class _Success implements RecoverPasswordState { + const factory _Success(String userId) = _$_Success; + + String get userId => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$SuccessCopyWith<_Success> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/recover_password_bloc/recover_password_event.dart b/lib/src/presentation/blocs/recover_password_bloc/recover_password_event.dart index 44b9b6b..fab603f 100644 --- a/lib/src/presentation/blocs/recover_password_bloc/recover_password_event.dart +++ b/lib/src/presentation/blocs/recover_password_bloc/recover_password_event.dart @@ -1,16 +1,14 @@ part of 'recover_password_bloc.dart'; -@immutable -abstract class RecoverPasswordEvent {} - -class RecoverPasswordCISubmit extends RecoverPasswordEvent { - final RecoverPasswordInitial state; - - RecoverPasswordCISubmit({required this.state}); -} - -class RecoverPasswordFinalSubmit extends RecoverPasswordEvent { - final RecoverPasswordQuestions state; - - RecoverPasswordFinalSubmit({required this.state}); +@freezed +class RecoverPasswordEvent with _$RecoverPasswordEvent { + const factory RecoverPasswordEvent.ciSubmit( + TextEditingController ci, + ) = _CISubmit; + const factory RecoverPasswordEvent.finalSubmit( + String ci, + List questions, + List answers, + TextEditingController password, + ) = _FinalSubmit; } diff --git a/lib/src/presentation/blocs/recover_password_bloc/recover_password_state.dart b/lib/src/presentation/blocs/recover_password_bloc/recover_password_state.dart index 4eaad48..63765ab 100644 --- a/lib/src/presentation/blocs/recover_password_bloc/recover_password_state.dart +++ b/lib/src/presentation/blocs/recover_password_bloc/recover_password_state.dart @@ -1,86 +1,33 @@ part of 'recover_password_bloc.dart'; -@immutable -abstract class RecoverPasswordState {} - -class RecoverPasswordError extends RecoverPasswordState { - final String error; - - RecoverPasswordError({required this.error}); -} - -class RecoverPasswordInitial extends RecoverPasswordState { - final TextEditingController ci; - - RecoverPasswordInitial({required this.ci}); -} - -class RecoverPasswordCILoading extends RecoverPasswordInitial { - RecoverPasswordCILoading({ - required TextEditingController ci, - }) : super(ci: ci); -} - -class RecoverPasswordCIError extends RecoverPasswordInitial - implements RecoverPasswordError { - @override - final String error; - - RecoverPasswordCIError({ - required TextEditingController ci, - required this.error, - }) : super(ci: ci); -} - -class RecoverPasswordQuestions extends RecoverPasswordState { - final String ci; - final List questions; - final List answers; - final TextEditingController password; - - RecoverPasswordQuestions({ - required this.ci, - required this.questions, - required this.answers, - required this.password, - }); -} - -class RecoverPasswordQuestionsLoading extends RecoverPasswordQuestions { - RecoverPasswordQuestionsLoading({ - required String ci, - required List questions, - required List answers, - required TextEditingController password, - }) : super( - ci: ci, - questions: questions, - answers: answers, - password: password, - ); -} - -class RecoverPasswordQuestionsError extends RecoverPasswordQuestions - implements RecoverPasswordError { - @override - final String error; - - RecoverPasswordQuestionsError({ - required String ci, - required List questions, - required List answers, - required TextEditingController password, - required this.error, - }) : super( - ci: ci, - questions: questions, - answers: answers, - password: password, - ); -} - -class RecoverPasswordSuccess extends RecoverPasswordState { - final String userId; - - RecoverPasswordSuccess({required this.userId}); +@freezed +class RecoverPasswordState with _$RecoverPasswordState { + const factory RecoverPasswordState.initial(TextEditingController ci) = + _Initial; + const factory RecoverPasswordState.ciLoading(TextEditingController ci) = + _CILoading; + const factory RecoverPasswordState.ciError( + TextEditingController ci, + String error, + ) = _CIError; + const factory RecoverPasswordState.questions( + String ci, + List questions, + List answers, + TextEditingController password, + ) = _Questions; + const factory RecoverPasswordState.questionsLoading( + String ci, + List questions, + List answers, + TextEditingController password, + ) = _QuestionsLoading; + const factory RecoverPasswordState.questionsError( + String ci, + List questions, + List answers, + TextEditingController password, + String error, + ) = _QuestionsError; + const factory RecoverPasswordState.success(String userId) = _Success; } diff --git a/lib/src/presentation/blocs/register_bloc/register_bloc.dart b/lib/src/presentation/blocs/register_bloc/register_bloc.dart index e09599f..a606add 100644 --- a/lib/src/presentation/blocs/register_bloc/register_bloc.dart +++ b/lib/src/presentation/blocs/register_bloc/register_bloc.dart @@ -1,58 +1,65 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:gestionuh/src/data/models/password_edit_data.dart'; -import 'package:gestionuh/src/data/repository/auth_repository/auth_repository.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'register_event.dart'; part 'register_state.dart'; +part 'register_bloc.freezed.dart'; class RegisterBloc extends Bloc { final AuthRepository repository; - RegisterBloc({required this.repository}) : super(RegisterInitial()); + RegisterBloc({required this.repository}) + : super(const RegisterState.initial()); @override Stream mapEventToState( RegisterEvent event, ) async* { - if (event is QuestionsRequestedRegister) { - yield* questionsRequestedRegisterHandler(event); - } - if (event is FormsEnteredRegister) { - yield* formsEnteredRegisterHandler(event); - } + yield* event.map( + questionsRequested: questionsRequestedRegisterHandler, + formSubmitted: formSubmittedRegisterHandler, + ); } Stream questionsRequestedRegisterHandler( - QuestionsRequestedRegister event) async* { - yield LoadInitialDataInProgress(); + _$QuestionsRequestedRegister _) async* { + yield const RegisterState.initialLoadInProgress(); final questions = await repository.getSecurityQuestions(); if (questions.error != null) { - yield LoadInitialDataFailure(error: questions.error!); + yield RegisterState.initialLoadFailure( + error: questions.error ?? Errors.DefaultError, + ); } else { - yield LoadInitialDataSuccess(questions: questions.questions!); + yield RegisterState.initialLoadSuccess(questions: questions.questions!); } - // } - Stream formsEnteredRegisterHandler( - FormsEnteredRegister event) async* { - yield RegisterUserInProgress(); + Stream formSubmittedRegisterHandler( + _$FormSubmittedRegister event, + ) async* { + yield const RegisterState.registrationInProgress(); if (event.passwordFirst != event.passwordSecond) { - yield const RegisterUserFailure(error: 'Las contraseñas no coinciden.'); + yield const RegisterState.registrationFailure( + error: 'Las contraseñas no coinciden.'); return; } final userId = await repository.sendRegistration(PasswordEditData( - answers: event.answers, - ci: event.ci, - password: event.passwordFirst, + answers: event.answers.map((e) => e.trim()).toList(), + ci: event.ci.trim(), + password: event.passwordFirst.trim(), questions: event.questions, )); if (userId.error != null) { - yield RegisterUserFailure(error: userId.error!); + yield RegisterState.registrationFailure( + error: userId.error ?? Errors.DefaultError, + ); } else { - yield RegisterUserSuccess(userEmail: userId.userId!); + yield RegisterState.registrationSuccess(userEmail: userId.userId!); } // diff --git a/lib/src/presentation/blocs/register_bloc/register_bloc.freezed.dart b/lib/src/presentation/blocs/register_bloc/register_bloc.freezed.dart new file mode 100644 index 0000000..afd8531 --- /dev/null +++ b/lib/src/presentation/blocs/register_bloc/register_bloc.freezed.dart @@ -0,0 +1,1428 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'register_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$RegisterEventTearOff { + const _$RegisterEventTearOff(); + + _$QuestionsRequestedRegister questionsRequested() { + return const _$QuestionsRequestedRegister(); + } + + _$FormSubmittedRegister formSubmitted( + {required List answers, + required String ci, + required String passwordFirst, + required String passwordSecond, + required List questions}) { + return _$FormSubmittedRegister( + answers: answers, + ci: ci, + passwordFirst: passwordFirst, + passwordSecond: passwordSecond, + questions: questions, + ); + } +} + +/// @nodoc +const $RegisterEvent = _$RegisterEventTearOff(); + +/// @nodoc +mixin _$RegisterEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() questionsRequested, + required TResult Function(List answers, String ci, + String passwordFirst, String passwordSecond, List questions) + formSubmitted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? questionsRequested, + TResult Function(List answers, String ci, String passwordFirst, + String passwordSecond, List questions)? + formSubmitted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$QuestionsRequestedRegister value) + questionsRequested, + required TResult Function(_$FormSubmittedRegister value) formSubmitted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$QuestionsRequestedRegister value)? questionsRequested, + TResult Function(_$FormSubmittedRegister value)? formSubmitted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RegisterEventCopyWith<$Res> { + factory $RegisterEventCopyWith( + RegisterEvent value, $Res Function(RegisterEvent) then) = + _$RegisterEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$RegisterEventCopyWithImpl<$Res> + implements $RegisterEventCopyWith<$Res> { + _$RegisterEventCopyWithImpl(this._value, this._then); + + final RegisterEvent _value; + // ignore: unused_field + final $Res Function(RegisterEvent) _then; +} + +/// @nodoc +abstract class _$$QuestionsRequestedRegisterCopyWith<$Res> { + factory _$$QuestionsRequestedRegisterCopyWith( + _$QuestionsRequestedRegister value, + $Res Function(_$QuestionsRequestedRegister) then) = + __$$QuestionsRequestedRegisterCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$QuestionsRequestedRegisterCopyWithImpl<$Res> + extends _$RegisterEventCopyWithImpl<$Res> + implements _$$QuestionsRequestedRegisterCopyWith<$Res> { + __$$QuestionsRequestedRegisterCopyWithImpl( + _$QuestionsRequestedRegister _value, + $Res Function(_$QuestionsRequestedRegister) _then) + : super(_value, (v) => _then(v as _$QuestionsRequestedRegister)); + + @override + _$QuestionsRequestedRegister get _value => + super._value as _$QuestionsRequestedRegister; +} + +/// @nodoc + +class _$_$QuestionsRequestedRegister implements _$QuestionsRequestedRegister { + const _$_$QuestionsRequestedRegister(); + + @override + String toString() { + return 'RegisterEvent.questionsRequested()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$QuestionsRequestedRegister); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() questionsRequested, + required TResult Function(List answers, String ci, + String passwordFirst, String passwordSecond, List questions) + formSubmitted, + }) { + return questionsRequested(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? questionsRequested, + TResult Function(List answers, String ci, String passwordFirst, + String passwordSecond, List questions)? + formSubmitted, + required TResult orElse(), + }) { + if (questionsRequested != null) { + return questionsRequested(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$QuestionsRequestedRegister value) + questionsRequested, + required TResult Function(_$FormSubmittedRegister value) formSubmitted, + }) { + return questionsRequested(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$QuestionsRequestedRegister value)? questionsRequested, + TResult Function(_$FormSubmittedRegister value)? formSubmitted, + required TResult orElse(), + }) { + if (questionsRequested != null) { + return questionsRequested(this); + } + return orElse(); + } +} + +abstract class _$QuestionsRequestedRegister implements RegisterEvent { + const factory _$QuestionsRequestedRegister() = _$_$QuestionsRequestedRegister; +} + +/// @nodoc +abstract class _$$FormSubmittedRegisterCopyWith<$Res> { + factory _$$FormSubmittedRegisterCopyWith(_$FormSubmittedRegister value, + $Res Function(_$FormSubmittedRegister) then) = + __$$FormSubmittedRegisterCopyWithImpl<$Res>; + $Res call( + {List answers, + String ci, + String passwordFirst, + String passwordSecond, + List questions}); +} + +/// @nodoc +class __$$FormSubmittedRegisterCopyWithImpl<$Res> + extends _$RegisterEventCopyWithImpl<$Res> + implements _$$FormSubmittedRegisterCopyWith<$Res> { + __$$FormSubmittedRegisterCopyWithImpl(_$FormSubmittedRegister _value, + $Res Function(_$FormSubmittedRegister) _then) + : super(_value, (v) => _then(v as _$FormSubmittedRegister)); + + @override + _$FormSubmittedRegister get _value => super._value as _$FormSubmittedRegister; + + @override + $Res call({ + Object? answers = freezed, + Object? ci = freezed, + Object? passwordFirst = freezed, + Object? passwordSecond = freezed, + Object? questions = freezed, + }) { + return _then(_$FormSubmittedRegister( + answers: answers == freezed + ? _value.answers + : answers // ignore: cast_nullable_to_non_nullable + as List, + ci: ci == freezed + ? _value.ci + : ci // ignore: cast_nullable_to_non_nullable + as String, + passwordFirst: passwordFirst == freezed + ? _value.passwordFirst + : passwordFirst // ignore: cast_nullable_to_non_nullable + as String, + passwordSecond: passwordSecond == freezed + ? _value.passwordSecond + : passwordSecond // ignore: cast_nullable_to_non_nullable + as String, + questions: questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_$FormSubmittedRegister implements _$FormSubmittedRegister { + const _$_$FormSubmittedRegister( + {required this.answers, + required this.ci, + required this.passwordFirst, + required this.passwordSecond, + required this.questions}); + + @override + final List answers; + @override + final String ci; + @override + final String passwordFirst; + @override + final String passwordSecond; + @override + final List questions; + + @override + String toString() { + return 'RegisterEvent.formSubmitted(answers: $answers, ci: $ci, passwordFirst: $passwordFirst, passwordSecond: $passwordSecond, questions: $questions)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$FormSubmittedRegister && + (identical(other.answers, answers) || + const DeepCollectionEquality() + .equals(other.answers, answers)) && + (identical(other.ci, ci) || + const DeepCollectionEquality().equals(other.ci, ci)) && + (identical(other.passwordFirst, passwordFirst) || + const DeepCollectionEquality() + .equals(other.passwordFirst, passwordFirst)) && + (identical(other.passwordSecond, passwordSecond) || + const DeepCollectionEquality() + .equals(other.passwordSecond, passwordSecond)) && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(answers) ^ + const DeepCollectionEquality().hash(ci) ^ + const DeepCollectionEquality().hash(passwordFirst) ^ + const DeepCollectionEquality().hash(passwordSecond) ^ + const DeepCollectionEquality().hash(questions); + + @JsonKey(ignore: true) + @override + _$$FormSubmittedRegisterCopyWith<_$FormSubmittedRegister> get copyWith => + __$$FormSubmittedRegisterCopyWithImpl<_$FormSubmittedRegister>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() questionsRequested, + required TResult Function(List answers, String ci, + String passwordFirst, String passwordSecond, List questions) + formSubmitted, + }) { + return formSubmitted(answers, ci, passwordFirst, passwordSecond, questions); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? questionsRequested, + TResult Function(List answers, String ci, String passwordFirst, + String passwordSecond, List questions)? + formSubmitted, + required TResult orElse(), + }) { + if (formSubmitted != null) { + return formSubmitted( + answers, ci, passwordFirst, passwordSecond, questions); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$QuestionsRequestedRegister value) + questionsRequested, + required TResult Function(_$FormSubmittedRegister value) formSubmitted, + }) { + return formSubmitted(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$QuestionsRequestedRegister value)? questionsRequested, + TResult Function(_$FormSubmittedRegister value)? formSubmitted, + required TResult orElse(), + }) { + if (formSubmitted != null) { + return formSubmitted(this); + } + return orElse(); + } +} + +abstract class _$FormSubmittedRegister implements RegisterEvent { + const factory _$FormSubmittedRegister( + {required List answers, + required String ci, + required String passwordFirst, + required String passwordSecond, + required List questions}) = _$_$FormSubmittedRegister; + + List get answers => throw _privateConstructorUsedError; + String get ci => throw _privateConstructorUsedError; + String get passwordFirst => throw _privateConstructorUsedError; + String get passwordSecond => throw _privateConstructorUsedError; + List get questions => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$FormSubmittedRegisterCopyWith<_$FormSubmittedRegister> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$RegisterStateTearOff { + const _$RegisterStateTearOff(); + + _$RegisterInitial initial() { + return const _$RegisterInitial(); + } + + _$RegisterLoadInitialDataInProgress initialLoadInProgress() { + return const _$RegisterLoadInitialDataInProgress(); + } + + _$RegisterLoadInitialDataFailure initialLoadFailure({required String error}) { + return _$RegisterLoadInitialDataFailure( + error: error, + ); + } + + _$RegisterLoadInitialDataSuccess initialLoadSuccess( + {required List questions}) { + return _$RegisterLoadInitialDataSuccess( + questions: questions, + ); + } + + _$RegisterUserInProgress registrationInProgress() { + return const _$RegisterUserInProgress(); + } + + _$RegisterUserFailure registrationFailure({required String error}) { + return _$RegisterUserFailure( + error: error, + ); + } + + _$RegisterUserSuccess registrationSuccess({required String userEmail}) { + return _$RegisterUserSuccess( + userEmail: userEmail, + ); + } +} + +/// @nodoc +const $RegisterState = _$RegisterStateTearOff(); + +/// @nodoc +mixin _$RegisterState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RegisterStateCopyWith<$Res> { + factory $RegisterStateCopyWith( + RegisterState value, $Res Function(RegisterState) then) = + _$RegisterStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$RegisterStateCopyWithImpl<$Res> + implements $RegisterStateCopyWith<$Res> { + _$RegisterStateCopyWithImpl(this._value, this._then); + + final RegisterState _value; + // ignore: unused_field + final $Res Function(RegisterState) _then; +} + +/// @nodoc +abstract class _$$RegisterInitialCopyWith<$Res> { + factory _$$RegisterInitialCopyWith( + _$RegisterInitial value, $Res Function(_$RegisterInitial) then) = + __$$RegisterInitialCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$RegisterInitialCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterInitialCopyWith<$Res> { + __$$RegisterInitialCopyWithImpl( + _$RegisterInitial _value, $Res Function(_$RegisterInitial) _then) + : super(_value, (v) => _then(v as _$RegisterInitial)); + + @override + _$RegisterInitial get _value => super._value as _$RegisterInitial; +} + +/// @nodoc + +class _$_$RegisterInitial implements _$RegisterInitial { + const _$_$RegisterInitial(); + + @override + String toString() { + return 'RegisterState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$RegisterInitial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _$RegisterInitial implements RegisterState { + const factory _$RegisterInitial() = _$_$RegisterInitial; +} + +/// @nodoc +abstract class _$$RegisterLoadInitialDataInProgressCopyWith<$Res> { + factory _$$RegisterLoadInitialDataInProgressCopyWith( + _$RegisterLoadInitialDataInProgress value, + $Res Function(_$RegisterLoadInitialDataInProgress) then) = + __$$RegisterLoadInitialDataInProgressCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$RegisterLoadInitialDataInProgressCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterLoadInitialDataInProgressCopyWith<$Res> { + __$$RegisterLoadInitialDataInProgressCopyWithImpl( + _$RegisterLoadInitialDataInProgress _value, + $Res Function(_$RegisterLoadInitialDataInProgress) _then) + : super(_value, (v) => _then(v as _$RegisterLoadInitialDataInProgress)); + + @override + _$RegisterLoadInitialDataInProgress get _value => + super._value as _$RegisterLoadInitialDataInProgress; +} + +/// @nodoc + +class _$_$RegisterLoadInitialDataInProgress + implements _$RegisterLoadInitialDataInProgress { + const _$_$RegisterLoadInitialDataInProgress(); + + @override + String toString() { + return 'RegisterState.initialLoadInProgress()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$RegisterLoadInitialDataInProgress); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return initialLoadInProgress(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadInProgress != null) { + return initialLoadInProgress(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return initialLoadInProgress(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadInProgress != null) { + return initialLoadInProgress(this); + } + return orElse(); + } +} + +abstract class _$RegisterLoadInitialDataInProgress implements RegisterState { + const factory _$RegisterLoadInitialDataInProgress() = + _$_$RegisterLoadInitialDataInProgress; +} + +/// @nodoc +abstract class _$$RegisterLoadInitialDataFailureCopyWith<$Res> { + factory _$$RegisterLoadInitialDataFailureCopyWith( + _$RegisterLoadInitialDataFailure value, + $Res Function(_$RegisterLoadInitialDataFailure) then) = + __$$RegisterLoadInitialDataFailureCopyWithImpl<$Res>; + $Res call({String error}); +} + +/// @nodoc +class __$$RegisterLoadInitialDataFailureCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterLoadInitialDataFailureCopyWith<$Res> { + __$$RegisterLoadInitialDataFailureCopyWithImpl( + _$RegisterLoadInitialDataFailure _value, + $Res Function(_$RegisterLoadInitialDataFailure) _then) + : super(_value, (v) => _then(v as _$RegisterLoadInitialDataFailure)); + + @override + _$RegisterLoadInitialDataFailure get _value => + super._value as _$RegisterLoadInitialDataFailure; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_$RegisterLoadInitialDataFailure( + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$RegisterLoadInitialDataFailure + implements _$RegisterLoadInitialDataFailure { + const _$_$RegisterLoadInitialDataFailure({required this.error}); + + @override + final String error; + + @override + String toString() { + return 'RegisterState.initialLoadFailure(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$RegisterLoadInitialDataFailure && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$$RegisterLoadInitialDataFailureCopyWith<_$RegisterLoadInitialDataFailure> + get copyWith => __$$RegisterLoadInitialDataFailureCopyWithImpl< + _$RegisterLoadInitialDataFailure>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return initialLoadFailure(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadFailure != null) { + return initialLoadFailure(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return initialLoadFailure(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadFailure != null) { + return initialLoadFailure(this); + } + return orElse(); + } +} + +abstract class _$RegisterLoadInitialDataFailure implements RegisterState { + const factory _$RegisterLoadInitialDataFailure({required String error}) = + _$_$RegisterLoadInitialDataFailure; + + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$RegisterLoadInitialDataFailureCopyWith<_$RegisterLoadInitialDataFailure> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$RegisterLoadInitialDataSuccessCopyWith<$Res> { + factory _$$RegisterLoadInitialDataSuccessCopyWith( + _$RegisterLoadInitialDataSuccess value, + $Res Function(_$RegisterLoadInitialDataSuccess) then) = + __$$RegisterLoadInitialDataSuccessCopyWithImpl<$Res>; + $Res call({List questions}); +} + +/// @nodoc +class __$$RegisterLoadInitialDataSuccessCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterLoadInitialDataSuccessCopyWith<$Res> { + __$$RegisterLoadInitialDataSuccessCopyWithImpl( + _$RegisterLoadInitialDataSuccess _value, + $Res Function(_$RegisterLoadInitialDataSuccess) _then) + : super(_value, (v) => _then(v as _$RegisterLoadInitialDataSuccess)); + + @override + _$RegisterLoadInitialDataSuccess get _value => + super._value as _$RegisterLoadInitialDataSuccess; + + @override + $Res call({ + Object? questions = freezed, + }) { + return _then(_$RegisterLoadInitialDataSuccess( + questions: questions == freezed + ? _value.questions + : questions // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$_$RegisterLoadInitialDataSuccess + implements _$RegisterLoadInitialDataSuccess { + const _$_$RegisterLoadInitialDataSuccess({required this.questions}); + + @override + final List questions; + + @override + String toString() { + return 'RegisterState.initialLoadSuccess(questions: $questions)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$RegisterLoadInitialDataSuccess && + (identical(other.questions, questions) || + const DeepCollectionEquality() + .equals(other.questions, questions))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(questions); + + @JsonKey(ignore: true) + @override + _$$RegisterLoadInitialDataSuccessCopyWith<_$RegisterLoadInitialDataSuccess> + get copyWith => __$$RegisterLoadInitialDataSuccessCopyWithImpl< + _$RegisterLoadInitialDataSuccess>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return initialLoadSuccess(questions); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadSuccess != null) { + return initialLoadSuccess(questions); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return initialLoadSuccess(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (initialLoadSuccess != null) { + return initialLoadSuccess(this); + } + return orElse(); + } +} + +abstract class _$RegisterLoadInitialDataSuccess implements RegisterState { + const factory _$RegisterLoadInitialDataSuccess( + {required List questions}) = _$_$RegisterLoadInitialDataSuccess; + + List get questions => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$RegisterLoadInitialDataSuccessCopyWith<_$RegisterLoadInitialDataSuccess> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$RegisterUserInProgressCopyWith<$Res> { + factory _$$RegisterUserInProgressCopyWith(_$RegisterUserInProgress value, + $Res Function(_$RegisterUserInProgress) then) = + __$$RegisterUserInProgressCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$RegisterUserInProgressCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterUserInProgressCopyWith<$Res> { + __$$RegisterUserInProgressCopyWithImpl(_$RegisterUserInProgress _value, + $Res Function(_$RegisterUserInProgress) _then) + : super(_value, (v) => _then(v as _$RegisterUserInProgress)); + + @override + _$RegisterUserInProgress get _value => + super._value as _$RegisterUserInProgress; +} + +/// @nodoc + +class _$_$RegisterUserInProgress implements _$RegisterUserInProgress { + const _$_$RegisterUserInProgress(); + + @override + String toString() { + return 'RegisterState.registrationInProgress()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$RegisterUserInProgress); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return registrationInProgress(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationInProgress != null) { + return registrationInProgress(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return registrationInProgress(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationInProgress != null) { + return registrationInProgress(this); + } + return orElse(); + } +} + +abstract class _$RegisterUserInProgress implements RegisterState { + const factory _$RegisterUserInProgress() = _$_$RegisterUserInProgress; +} + +/// @nodoc +abstract class _$$RegisterUserFailureCopyWith<$Res> { + factory _$$RegisterUserFailureCopyWith(_$RegisterUserFailure value, + $Res Function(_$RegisterUserFailure) then) = + __$$RegisterUserFailureCopyWithImpl<$Res>; + $Res call({String error}); +} + +/// @nodoc +class __$$RegisterUserFailureCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterUserFailureCopyWith<$Res> { + __$$RegisterUserFailureCopyWithImpl( + _$RegisterUserFailure _value, $Res Function(_$RegisterUserFailure) _then) + : super(_value, (v) => _then(v as _$RegisterUserFailure)); + + @override + _$RegisterUserFailure get _value => super._value as _$RegisterUserFailure; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_$RegisterUserFailure( + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$RegisterUserFailure implements _$RegisterUserFailure { + const _$_$RegisterUserFailure({required this.error}); + + @override + final String error; + + @override + String toString() { + return 'RegisterState.registrationFailure(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$RegisterUserFailure && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$$RegisterUserFailureCopyWith<_$RegisterUserFailure> get copyWith => + __$$RegisterUserFailureCopyWithImpl<_$RegisterUserFailure>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return registrationFailure(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationFailure != null) { + return registrationFailure(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return registrationFailure(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationFailure != null) { + return registrationFailure(this); + } + return orElse(); + } +} + +abstract class _$RegisterUserFailure implements RegisterState { + const factory _$RegisterUserFailure({required String error}) = + _$_$RegisterUserFailure; + + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$RegisterUserFailureCopyWith<_$RegisterUserFailure> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$RegisterUserSuccessCopyWith<$Res> { + factory _$$RegisterUserSuccessCopyWith(_$RegisterUserSuccess value, + $Res Function(_$RegisterUserSuccess) then) = + __$$RegisterUserSuccessCopyWithImpl<$Res>; + $Res call({String userEmail}); +} + +/// @nodoc +class __$$RegisterUserSuccessCopyWithImpl<$Res> + extends _$RegisterStateCopyWithImpl<$Res> + implements _$$RegisterUserSuccessCopyWith<$Res> { + __$$RegisterUserSuccessCopyWithImpl( + _$RegisterUserSuccess _value, $Res Function(_$RegisterUserSuccess) _then) + : super(_value, (v) => _then(v as _$RegisterUserSuccess)); + + @override + _$RegisterUserSuccess get _value => super._value as _$RegisterUserSuccess; + + @override + $Res call({ + Object? userEmail = freezed, + }) { + return _then(_$RegisterUserSuccess( + userEmail: userEmail == freezed + ? _value.userEmail + : userEmail // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$RegisterUserSuccess implements _$RegisterUserSuccess { + const _$_$RegisterUserSuccess({required this.userEmail}); + + @override + final String userEmail; + + @override + String toString() { + return 'RegisterState.registrationSuccess(userEmail: $userEmail)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$RegisterUserSuccess && + (identical(other.userEmail, userEmail) || + const DeepCollectionEquality() + .equals(other.userEmail, userEmail))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(userEmail); + + @JsonKey(ignore: true) + @override + _$$RegisterUserSuccessCopyWith<_$RegisterUserSuccess> get copyWith => + __$$RegisterUserSuccessCopyWithImpl<_$RegisterUserSuccess>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() initialLoadInProgress, + required TResult Function(String error) initialLoadFailure, + required TResult Function(List questions) initialLoadSuccess, + required TResult Function() registrationInProgress, + required TResult Function(String error) registrationFailure, + required TResult Function(String userEmail) registrationSuccess, + }) { + return registrationSuccess(userEmail); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? initialLoadInProgress, + TResult Function(String error)? initialLoadFailure, + TResult Function(List questions)? initialLoadSuccess, + TResult Function()? registrationInProgress, + TResult Function(String error)? registrationFailure, + TResult Function(String userEmail)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationSuccess != null) { + return registrationSuccess(userEmail); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$RegisterInitial value) initial, + required TResult Function(_$RegisterLoadInitialDataInProgress value) + initialLoadInProgress, + required TResult Function(_$RegisterLoadInitialDataFailure value) + initialLoadFailure, + required TResult Function(_$RegisterLoadInitialDataSuccess value) + initialLoadSuccess, + required TResult Function(_$RegisterUserInProgress value) + registrationInProgress, + required TResult Function(_$RegisterUserFailure value) registrationFailure, + required TResult Function(_$RegisterUserSuccess value) registrationSuccess, + }) { + return registrationSuccess(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$RegisterInitial value)? initial, + TResult Function(_$RegisterLoadInitialDataInProgress value)? + initialLoadInProgress, + TResult Function(_$RegisterLoadInitialDataFailure value)? + initialLoadFailure, + TResult Function(_$RegisterLoadInitialDataSuccess value)? + initialLoadSuccess, + TResult Function(_$RegisterUserInProgress value)? registrationInProgress, + TResult Function(_$RegisterUserFailure value)? registrationFailure, + TResult Function(_$RegisterUserSuccess value)? registrationSuccess, + required TResult orElse(), + }) { + if (registrationSuccess != null) { + return registrationSuccess(this); + } + return orElse(); + } +} + +abstract class _$RegisterUserSuccess implements RegisterState { + const factory _$RegisterUserSuccess({required String userEmail}) = + _$_$RegisterUserSuccess; + + String get userEmail => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$RegisterUserSuccessCopyWith<_$RegisterUserSuccess> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/register_bloc/register_event.dart b/lib/src/presentation/blocs/register_bloc/register_event.dart index f0a7958..4bf4e8d 100644 --- a/lib/src/presentation/blocs/register_bloc/register_event.dart +++ b/lib/src/presentation/blocs/register_bloc/register_event.dart @@ -1,23 +1,14 @@ part of 'register_bloc.dart'; -abstract class RegisterEvent { - const RegisterEvent(); -} - -class QuestionsRequestedRegister extends RegisterEvent {} - -class FormsEnteredRegister extends RegisterEvent { - final List answers; - final String ci; - final String passwordFirst; - final String passwordSecond; - final List questions; - - const FormsEnteredRegister({ - required this.answers, - required this.ci, - required this.passwordFirst, - required this.passwordSecond, - required this.questions, - }); +@freezed +abstract class RegisterEvent with _$RegisterEvent { + const factory RegisterEvent.questionsRequested() = + _$QuestionsRequestedRegister; + const factory RegisterEvent.formSubmitted({ + required List answers, + required String ci, + required String passwordFirst, + required String passwordSecond, + required List questions, + }) = _$FormSubmittedRegister; } diff --git a/lib/src/presentation/blocs/register_bloc/register_state.dart b/lib/src/presentation/blocs/register_bloc/register_state.dart index 73f4ef0..96d04a5 100644 --- a/lib/src/presentation/blocs/register_bloc/register_state.dart +++ b/lib/src/presentation/blocs/register_bloc/register_state.dart @@ -1,43 +1,18 @@ part of 'register_bloc.dart'; -abstract class RegisterState { - const RegisterState(); -} - -class RegisterInitial extends RegisterState {} - -class LoadInitialDataInProgress extends RegisterState {} - -class LoadInitialDataFailure extends RegisterState { - final String error; - - const LoadInitialDataFailure({ - required this.error, - }); -} - -class LoadInitialDataSuccess extends RegisterState { - final List questions; - - const LoadInitialDataSuccess({ - required this.questions, - }); -} - -class RegisterUserInProgress extends RegisterState {} - -class RegisterUserFailure extends RegisterState { - final String error; - - const RegisterUserFailure({ - required this.error, - }); -} - -class RegisterUserSuccess extends RegisterState { - final String userEmail; - - const RegisterUserSuccess({ - required this.userEmail, - }); +@freezed +abstract class RegisterState with _$RegisterState { + const factory RegisterState.initial() = _$RegisterInitial; + const factory RegisterState.initialLoadInProgress() = + _$RegisterLoadInitialDataInProgress; + const factory RegisterState.initialLoadFailure({required String error}) = + _$RegisterLoadInitialDataFailure; + const factory RegisterState.initialLoadSuccess( + {required List questions}) = _$RegisterLoadInitialDataSuccess; + const factory RegisterState.registrationInProgress() = + _$RegisterUserInProgress; + const factory RegisterState.registrationFailure({required String error}) = + _$RegisterUserFailure; + const factory RegisterState.registrationSuccess({required String userEmail}) = + _$RegisterUserSuccess; } diff --git a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart index c2737c3..86e4af9 100644 --- a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart +++ b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart @@ -1,40 +1,46 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; -import 'package:gestionuh/src/data/repository.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; part 'resetpassword_event.dart'; part 'resetpassword_state.dart'; +part 'resetpassword_bloc.freezed.dart'; class ResetPasswordBloc extends Bloc { final AuthRepository authRepository; ResetPasswordBloc({ required this.authRepository, - }) : super(const ResetPasswordInitial(error: '')); + }) : super(const ResetPasswordState.initial()); @override Stream mapEventToState( ResetPasswordEvent event, ) async* { - if (event is ResetPasswordAttempted) { - yield* resetPasswordAttemptedHandler(event); - } + yield* event.map(resetPasswordAttempted: resetPasswordAttemptedHandler); } Stream resetPasswordAttemptedHandler( - ResetPasswordAttempted event) async* { - yield ResetPasswordInProgress(); + _$ResetPasswordAttempted event, + ) async* { + yield const ResetPasswordState.inProgress(); if (event.passwordFirst != event.passwordSecond) { - yield const ResetPasswordInitial(error: 'Las contraseñas no coinciden.'); + yield const ResetPasswordState.failure( + error: 'Las contraseñas no coinciden.'); return; } - final status = await authRepository.resetPassword(event.passwordFirst); + final status = await authRepository.resetPassword( + event.currentPassword.trim(), + event.passwordFirst.trim(), + ); if (status.status ?? false) { - yield ResetPasswordSuccess(); + yield const ResetPasswordState.success(); } else { - yield ResetPasswordInitial( - error: status.error ?? 'Ocurrió un error, intente de nuevo.', + yield ResetPasswordState.failure( + error: status.error ?? Errors.DefaultError, ); } } diff --git a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.freezed.dart b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.freezed.dart new file mode 100644 index 0000000..bb829ca --- /dev/null +++ b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.freezed.dart @@ -0,0 +1,764 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'resetpassword_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$ResetPasswordEventTearOff { + const _$ResetPasswordEventTearOff(); + + _$ResetPasswordAttempted resetPasswordAttempted( + {required String currentPassword, + required String passwordFirst, + required String passwordSecond}) { + return _$ResetPasswordAttempted( + currentPassword: currentPassword, + passwordFirst: passwordFirst, + passwordSecond: passwordSecond, + ); + } +} + +/// @nodoc +const $ResetPasswordEvent = _$ResetPasswordEventTearOff(); + +/// @nodoc +mixin _$ResetPasswordEvent { + String get currentPassword => throw _privateConstructorUsedError; + String get passwordFirst => throw _privateConstructorUsedError; + String get passwordSecond => throw _privateConstructorUsedError; + + @optionalTypeArgs + TResult when({ + required TResult Function( + String currentPassword, String passwordFirst, String passwordSecond) + resetPasswordAttempted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String currentPassword, String passwordFirst, + String passwordSecond)? + resetPasswordAttempted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordAttempted value) + resetPasswordAttempted, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordAttempted value)? resetPasswordAttempted, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $ResetPasswordEventCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ResetPasswordEventCopyWith<$Res> { + factory $ResetPasswordEventCopyWith( + ResetPasswordEvent value, $Res Function(ResetPasswordEvent) then) = + _$ResetPasswordEventCopyWithImpl<$Res>; + $Res call( + {String currentPassword, String passwordFirst, String passwordSecond}); +} + +/// @nodoc +class _$ResetPasswordEventCopyWithImpl<$Res> + implements $ResetPasswordEventCopyWith<$Res> { + _$ResetPasswordEventCopyWithImpl(this._value, this._then); + + final ResetPasswordEvent _value; + // ignore: unused_field + final $Res Function(ResetPasswordEvent) _then; + + @override + $Res call({ + Object? currentPassword = freezed, + Object? passwordFirst = freezed, + Object? passwordSecond = freezed, + }) { + return _then(_value.copyWith( + currentPassword: currentPassword == freezed + ? _value.currentPassword + : currentPassword // ignore: cast_nullable_to_non_nullable + as String, + passwordFirst: passwordFirst == freezed + ? _value.passwordFirst + : passwordFirst // ignore: cast_nullable_to_non_nullable + as String, + passwordSecond: passwordSecond == freezed + ? _value.passwordSecond + : passwordSecond // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +abstract class _$$ResetPasswordAttemptedCopyWith<$Res> + implements $ResetPasswordEventCopyWith<$Res> { + factory _$$ResetPasswordAttemptedCopyWith(_$ResetPasswordAttempted value, + $Res Function(_$ResetPasswordAttempted) then) = + __$$ResetPasswordAttemptedCopyWithImpl<$Res>; + @override + $Res call( + {String currentPassword, String passwordFirst, String passwordSecond}); +} + +/// @nodoc +class __$$ResetPasswordAttemptedCopyWithImpl<$Res> + extends _$ResetPasswordEventCopyWithImpl<$Res> + implements _$$ResetPasswordAttemptedCopyWith<$Res> { + __$$ResetPasswordAttemptedCopyWithImpl(_$ResetPasswordAttempted _value, + $Res Function(_$ResetPasswordAttempted) _then) + : super(_value, (v) => _then(v as _$ResetPasswordAttempted)); + + @override + _$ResetPasswordAttempted get _value => + super._value as _$ResetPasswordAttempted; + + @override + $Res call({ + Object? currentPassword = freezed, + Object? passwordFirst = freezed, + Object? passwordSecond = freezed, + }) { + return _then(_$ResetPasswordAttempted( + currentPassword: currentPassword == freezed + ? _value.currentPassword + : currentPassword // ignore: cast_nullable_to_non_nullable + as String, + passwordFirst: passwordFirst == freezed + ? _value.passwordFirst + : passwordFirst // ignore: cast_nullable_to_non_nullable + as String, + passwordSecond: passwordSecond == freezed + ? _value.passwordSecond + : passwordSecond // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$ResetPasswordAttempted implements _$ResetPasswordAttempted { + const _$_$ResetPasswordAttempted( + {required this.currentPassword, + required this.passwordFirst, + required this.passwordSecond}); + + @override + final String currentPassword; + @override + final String passwordFirst; + @override + final String passwordSecond; + + @override + String toString() { + return 'ResetPasswordEvent.resetPasswordAttempted(currentPassword: $currentPassword, passwordFirst: $passwordFirst, passwordSecond: $passwordSecond)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$ResetPasswordAttempted && + (identical(other.currentPassword, currentPassword) || + const DeepCollectionEquality() + .equals(other.currentPassword, currentPassword)) && + (identical(other.passwordFirst, passwordFirst) || + const DeepCollectionEquality() + .equals(other.passwordFirst, passwordFirst)) && + (identical(other.passwordSecond, passwordSecond) || + const DeepCollectionEquality() + .equals(other.passwordSecond, passwordSecond))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(currentPassword) ^ + const DeepCollectionEquality().hash(passwordFirst) ^ + const DeepCollectionEquality().hash(passwordSecond); + + @JsonKey(ignore: true) + @override + _$$ResetPasswordAttemptedCopyWith<_$ResetPasswordAttempted> get copyWith => + __$$ResetPasswordAttemptedCopyWithImpl<_$ResetPasswordAttempted>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function( + String currentPassword, String passwordFirst, String passwordSecond) + resetPasswordAttempted, + }) { + return resetPasswordAttempted( + currentPassword, passwordFirst, passwordSecond); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String currentPassword, String passwordFirst, + String passwordSecond)? + resetPasswordAttempted, + required TResult orElse(), + }) { + if (resetPasswordAttempted != null) { + return resetPasswordAttempted( + currentPassword, passwordFirst, passwordSecond); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordAttempted value) + resetPasswordAttempted, + }) { + return resetPasswordAttempted(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordAttempted value)? resetPasswordAttempted, + required TResult orElse(), + }) { + if (resetPasswordAttempted != null) { + return resetPasswordAttempted(this); + } + return orElse(); + } +} + +abstract class _$ResetPasswordAttempted implements ResetPasswordEvent { + const factory _$ResetPasswordAttempted( + {required String currentPassword, + required String passwordFirst, + required String passwordSecond}) = _$_$ResetPasswordAttempted; + + @override + String get currentPassword => throw _privateConstructorUsedError; + @override + String get passwordFirst => throw _privateConstructorUsedError; + @override + String get passwordSecond => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$$ResetPasswordAttemptedCopyWith<_$ResetPasswordAttempted> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +class _$ResetPasswordStateTearOff { + const _$ResetPasswordStateTearOff(); + + _$ResetPasswordInitialState initial() { + return const _$ResetPasswordInitialState(); + } + + _$ResetPasswordInProgress inProgress() { + return const _$ResetPasswordInProgress(); + } + + _$ResetPasswordSuccess success() { + return const _$ResetPasswordSuccess(); + } + + _$ResetPasswordFailure failure({required String error}) { + return _$ResetPasswordFailure( + error: error, + ); + } +} + +/// @nodoc +const $ResetPasswordState = _$ResetPasswordStateTearOff(); + +/// @nodoc +mixin _$ResetPasswordState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordInitialState value) initial, + required TResult Function(_$ResetPasswordInProgress value) inProgress, + required TResult Function(_$ResetPasswordSuccess value) success, + required TResult Function(_$ResetPasswordFailure value) failure, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordInitialState value)? initial, + TResult Function(_$ResetPasswordInProgress value)? inProgress, + TResult Function(_$ResetPasswordSuccess value)? success, + TResult Function(_$ResetPasswordFailure value)? failure, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ResetPasswordStateCopyWith<$Res> { + factory $ResetPasswordStateCopyWith( + ResetPasswordState value, $Res Function(ResetPasswordState) then) = + _$ResetPasswordStateCopyWithImpl<$Res>; +} + +/// @nodoc +class _$ResetPasswordStateCopyWithImpl<$Res> + implements $ResetPasswordStateCopyWith<$Res> { + _$ResetPasswordStateCopyWithImpl(this._value, this._then); + + final ResetPasswordState _value; + // ignore: unused_field + final $Res Function(ResetPasswordState) _then; +} + +/// @nodoc +abstract class _$$ResetPasswordInitialStateCopyWith<$Res> { + factory _$$ResetPasswordInitialStateCopyWith( + _$ResetPasswordInitialState value, + $Res Function(_$ResetPasswordInitialState) then) = + __$$ResetPasswordInitialStateCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$ResetPasswordInitialStateCopyWithImpl<$Res> + extends _$ResetPasswordStateCopyWithImpl<$Res> + implements _$$ResetPasswordInitialStateCopyWith<$Res> { + __$$ResetPasswordInitialStateCopyWithImpl(_$ResetPasswordInitialState _value, + $Res Function(_$ResetPasswordInitialState) _then) + : super(_value, (v) => _then(v as _$ResetPasswordInitialState)); + + @override + _$ResetPasswordInitialState get _value => + super._value as _$ResetPasswordInitialState; +} + +/// @nodoc + +class _$_$ResetPasswordInitialState implements _$ResetPasswordInitialState { + const _$_$ResetPasswordInitialState(); + + @override + String toString() { + return 'ResetPasswordState.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$ResetPasswordInitialState); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordInitialState value) initial, + required TResult Function(_$ResetPasswordInProgress value) inProgress, + required TResult Function(_$ResetPasswordSuccess value) success, + required TResult Function(_$ResetPasswordFailure value) failure, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordInitialState value)? initial, + TResult Function(_$ResetPasswordInProgress value)? inProgress, + TResult Function(_$ResetPasswordSuccess value)? success, + TResult Function(_$ResetPasswordFailure value)? failure, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _$ResetPasswordInitialState implements ResetPasswordState { + const factory _$ResetPasswordInitialState() = _$_$ResetPasswordInitialState; +} + +/// @nodoc +abstract class _$$ResetPasswordInProgressCopyWith<$Res> { + factory _$$ResetPasswordInProgressCopyWith(_$ResetPasswordInProgress value, + $Res Function(_$ResetPasswordInProgress) then) = + __$$ResetPasswordInProgressCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$ResetPasswordInProgressCopyWithImpl<$Res> + extends _$ResetPasswordStateCopyWithImpl<$Res> + implements _$$ResetPasswordInProgressCopyWith<$Res> { + __$$ResetPasswordInProgressCopyWithImpl(_$ResetPasswordInProgress _value, + $Res Function(_$ResetPasswordInProgress) _then) + : super(_value, (v) => _then(v as _$ResetPasswordInProgress)); + + @override + _$ResetPasswordInProgress get _value => + super._value as _$ResetPasswordInProgress; +} + +/// @nodoc + +class _$_$ResetPasswordInProgress implements _$ResetPasswordInProgress { + const _$_$ResetPasswordInProgress(); + + @override + String toString() { + return 'ResetPasswordState.inProgress()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$ResetPasswordInProgress); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return inProgress(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordInitialState value) initial, + required TResult Function(_$ResetPasswordInProgress value) inProgress, + required TResult Function(_$ResetPasswordSuccess value) success, + required TResult Function(_$ResetPasswordFailure value) failure, + }) { + return inProgress(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordInitialState value)? initial, + TResult Function(_$ResetPasswordInProgress value)? inProgress, + TResult Function(_$ResetPasswordSuccess value)? success, + TResult Function(_$ResetPasswordFailure value)? failure, + required TResult orElse(), + }) { + if (inProgress != null) { + return inProgress(this); + } + return orElse(); + } +} + +abstract class _$ResetPasswordInProgress implements ResetPasswordState { + const factory _$ResetPasswordInProgress() = _$_$ResetPasswordInProgress; +} + +/// @nodoc +abstract class _$$ResetPasswordSuccessCopyWith<$Res> { + factory _$$ResetPasswordSuccessCopyWith(_$ResetPasswordSuccess value, + $Res Function(_$ResetPasswordSuccess) then) = + __$$ResetPasswordSuccessCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$ResetPasswordSuccessCopyWithImpl<$Res> + extends _$ResetPasswordStateCopyWithImpl<$Res> + implements _$$ResetPasswordSuccessCopyWith<$Res> { + __$$ResetPasswordSuccessCopyWithImpl(_$ResetPasswordSuccess _value, + $Res Function(_$ResetPasswordSuccess) _then) + : super(_value, (v) => _then(v as _$ResetPasswordSuccess)); + + @override + _$ResetPasswordSuccess get _value => super._value as _$ResetPasswordSuccess; +} + +/// @nodoc + +class _$_$ResetPasswordSuccess implements _$ResetPasswordSuccess { + const _$_$ResetPasswordSuccess(); + + @override + String toString() { + return 'ResetPasswordState.success()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is _$ResetPasswordSuccess); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return success(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (success != null) { + return success(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordInitialState value) initial, + required TResult Function(_$ResetPasswordInProgress value) inProgress, + required TResult Function(_$ResetPasswordSuccess value) success, + required TResult Function(_$ResetPasswordFailure value) failure, + }) { + return success(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordInitialState value)? initial, + TResult Function(_$ResetPasswordInProgress value)? inProgress, + TResult Function(_$ResetPasswordSuccess value)? success, + TResult Function(_$ResetPasswordFailure value)? failure, + required TResult orElse(), + }) { + if (success != null) { + return success(this); + } + return orElse(); + } +} + +abstract class _$ResetPasswordSuccess implements ResetPasswordState { + const factory _$ResetPasswordSuccess() = _$_$ResetPasswordSuccess; +} + +/// @nodoc +abstract class _$$ResetPasswordFailureCopyWith<$Res> { + factory _$$ResetPasswordFailureCopyWith(_$ResetPasswordFailure value, + $Res Function(_$ResetPasswordFailure) then) = + __$$ResetPasswordFailureCopyWithImpl<$Res>; + $Res call({String error}); +} + +/// @nodoc +class __$$ResetPasswordFailureCopyWithImpl<$Res> + extends _$ResetPasswordStateCopyWithImpl<$Res> + implements _$$ResetPasswordFailureCopyWith<$Res> { + __$$ResetPasswordFailureCopyWithImpl(_$ResetPasswordFailure _value, + $Res Function(_$ResetPasswordFailure) _then) + : super(_value, (v) => _then(v as _$ResetPasswordFailure)); + + @override + _$ResetPasswordFailure get _value => super._value as _$ResetPasswordFailure; + + @override + $Res call({ + Object? error = freezed, + }) { + return _then(_$ResetPasswordFailure( + error: error == freezed + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$_$ResetPasswordFailure implements _$ResetPasswordFailure { + const _$_$ResetPasswordFailure({required this.error}); + + @override + final String error; + + @override + String toString() { + return 'ResetPasswordState.failure(error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _$ResetPasswordFailure && + (identical(other.error, error) || + const DeepCollectionEquality().equals(other.error, error))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(error); + + @JsonKey(ignore: true) + @override + _$$ResetPasswordFailureCopyWith<_$ResetPasswordFailure> get copyWith => + __$$ResetPasswordFailureCopyWithImpl<_$ResetPasswordFailure>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() inProgress, + required TResult Function() success, + required TResult Function(String error) failure, + }) { + return failure(error); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? inProgress, + TResult Function()? success, + TResult Function(String error)? failure, + required TResult orElse(), + }) { + if (failure != null) { + return failure(error); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_$ResetPasswordInitialState value) initial, + required TResult Function(_$ResetPasswordInProgress value) inProgress, + required TResult Function(_$ResetPasswordSuccess value) success, + required TResult Function(_$ResetPasswordFailure value) failure, + }) { + return failure(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_$ResetPasswordInitialState value)? initial, + TResult Function(_$ResetPasswordInProgress value)? inProgress, + TResult Function(_$ResetPasswordSuccess value)? success, + TResult Function(_$ResetPasswordFailure value)? failure, + required TResult orElse(), + }) { + if (failure != null) { + return failure(this); + } + return orElse(); + } +} + +abstract class _$ResetPasswordFailure implements ResetPasswordState { + const factory _$ResetPasswordFailure({required String error}) = + _$_$ResetPasswordFailure; + + String get error => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + _$$ResetPasswordFailureCopyWith<_$ResetPasswordFailure> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_event.dart b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_event.dart index a97ffa9..6042623 100644 --- a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_event.dart +++ b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_event.dart @@ -1,15 +1,10 @@ part of 'resetpassword_bloc.dart'; -abstract class ResetPasswordEvent { - const ResetPasswordEvent(); -} - -class ResetPasswordAttempted extends ResetPasswordEvent { - final String passwordFirst; - final String passwordSecond; - - const ResetPasswordAttempted({ - required this.passwordFirst, - required this.passwordSecond, - }); +@freezed +class ResetPasswordEvent with _$ResetPasswordEvent { + const factory ResetPasswordEvent.resetPasswordAttempted({ + required String currentPassword, + required String passwordFirst, + required String passwordSecond, + }) = _$ResetPasswordAttempted; } diff --git a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_state.dart b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_state.dart index a8b1c1f..c5c9d47 100644 --- a/lib/src/presentation/blocs/reset_password_bloc/resetpassword_state.dart +++ b/lib/src/presentation/blocs/reset_password_bloc/resetpassword_state.dart @@ -1,15 +1,10 @@ part of 'resetpassword_bloc.dart'; -abstract class ResetPasswordState { - const ResetPasswordState(); +@freezed +abstract class ResetPasswordState with _$ResetPasswordState { + const factory ResetPasswordState.initial() = _$ResetPasswordInitialState; + const factory ResetPasswordState.inProgress() = _$ResetPasswordInProgress; + const factory ResetPasswordState.success() = _$ResetPasswordSuccess; + const factory ResetPasswordState.failure({required String error}) = + _$ResetPasswordFailure; } - -class ResetPasswordInitial extends ResetPasswordState { - final String error; - - const ResetPasswordInitial({required this.error}) : super(); -} - -class ResetPasswordInProgress extends ResetPasswordState {} - -class ResetPasswordSuccess extends ResetPasswordState {} diff --git a/lib/src/presentation/pages.dart b/lib/src/presentation/pages.dart deleted file mode 100644 index c160033..0000000 --- a/lib/src/presentation/pages.dart +++ /dev/null @@ -1,6 +0,0 @@ -export 'pages/login_page.dart'; -export 'pages/mail_quotas_page.dart'; -export 'pages/profile_page.dart'; -export 'pages/quota_page.dart'; -export 'pages/recover_password_page.dart'; -export 'pages/reset_password_page.dart'; diff --git a/lib/src/presentation/pages/about_page.dart b/lib/src/presentation/pages/about_page.dart deleted file mode 100644 index fe1a8cb..0000000 --- a/lib/src/presentation/pages/about_page.dart +++ /dev/null @@ -1,182 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:gestionuh/src/presentation/widgets/flash_helper.dart'; -import 'package:gestionuh/src/utils/constants.dart'; -import 'package:url_launcher/url_launcher.dart'; - -class AboutInformationPage extends StatelessWidget { - const AboutInformationPage({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Acerca de GestiónUH'), - centerTitle: true, - ), - bottomSheet: Center( - heightFactor: 1, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - '\u00a9 2021${Constants.copyRight}', - textAlign: TextAlign.center, - style: - Theme.of(context).textTheme.headline6!.copyWith(fontSize: 12), - ), - ], - ), - ), - body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox( - height: 20, - ), - Center( - child: Image.asset( - 'assets/images/logo-uh.png', - color: Theme.of(context).primaryColor, - ), - ), - const SizedBox( - height: 20, - ), - Text( - About.shortDescription, - style: Theme.of(context) - .textTheme - .headline6! - .copyWith(fontSize: 15, color: Colors.black38), - ), - const SizedBox( - height: 50, - ), - Text( - 'Equipo de desarrollo:', - style: Theme.of(context).textTheme.headline5!.copyWith(), - ), - const SizedBox( - height: 30, - ), - Column( - children: Developers.teams.keys - .map((key) => ExpansionTile( - title: Text(key), - children: Developers.teams[key]! - .map((e) => ListTile( - title: Text( - e.name, - style: Theme.of(context) - .textTheme - .headline6! - .copyWith(fontSize: 14), - ), - subtitle: Text( - e.role, - style: Theme.of(context) - .textTheme - .bodyText1! - .copyWith(fontSize: 12), - ), - onTap: e.link == null - ? null - : () async { - if (await canLaunch(e.link!)) { - await launch(e.link!); - } else { - FlashHelper.errorBar( - context, - message: - 'No puede acceder a ${e.link}', - ); - } - }, - trailing: e.link != null - ? const Icon(Icons.link_off_outlined) - : null, - )) - .toList(), - )) - .toList(), - ), - const SizedBox(height: 50), - Text( - 'Nodo Central de Red - UH', - style: Theme.of(context).textTheme.headline6!.copyWith(), - ), - const SizedBox(height: 10), - Text( - 'MATCOM - UH', - style: Theme.of(context).textTheme.headline6!.copyWith(), - ), - const SizedBox(height: 10), - Text( - 'GRS - UH', - style: Theme.of(context).textTheme.headline6!.copyWith(), - ), - GestureDetector( - onTap: () async { - const url = - 'https://raw.githubusercontent.com/covid19cuba/covid19cuba-app/master/LICENSE'; - if (await canLaunch(url)) { - await launch(url); - } else { - FlashHelper.errorBar( - context, - message: 'No puede acceder a $url', - ); - } - }, - child: Container( - padding: - const EdgeInsets.symmetric(horizontal: 20, vertical: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Copyright 2021', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle2, - ), - Container( - padding: const EdgeInsets.all(2), - ), - Icon( - Icons.copyright, - color: Theme.of(context).textTheme.subtitle2!.color, - ), - Container( - padding: const EdgeInsets.all(2), - ), - Text( - 'GPL-3.0', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle2, - ), - ], - ), - ), - ) - ], - ), - ), - ), - ); - } -} - -class DeveloperInfo { - final String? name; - final String? role; - final String? link; - - const DeveloperInfo({ - this.name, - this.role, - this.link, - }); -} diff --git a/lib/src/presentation/pages/home_page/home_page.dart b/lib/src/presentation/pages/home_page/home_page.dart new file mode 100644 index 0000000..6be6c5e --- /dev/null +++ b/lib/src/presentation/pages/home_page/home_page.dart @@ -0,0 +1,308 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/data/enums/enums.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/pages/home_page/sub_pages/sub_pages.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +import 'package:get_it/get_it.dart'; + +class HomePage extends StatelessWidget { + @override + Widget build(BuildContext context) { + return BlocListener( + listener: _buildListener, + child: Scaffold( + appBar: _buildAppBar(), + drawer: _buildDrawer(context), + body: _buildBody(context), + ), + ); + } + + void _buildListener(BuildContext context, HomeState state) { + state.maybeWhen( + logout: () { + Navigator.of(context).pushNamedAndRemoveUntil( + LOGIN_ROUTE_NAME, + (route) => false, + ); + }, + orElse: () {}, + ); + } + + PreferredSizeWidget _buildAppBar() { + return AppBar( + title: BlocBuilder( + builder: (context, state) { + return Text( + state.map( + loading: (state) => 'Cargando', + error: (state) => 'Error', + logout: (state) => 'Cargando', + profile: (state) => 'Perfil', + quota: (state) => 'Mi Cuota', + mailQuota: (state) => 'Correo', + resetPassword: (state) => 'Cambiar Contraseña', + aboutUs: (state) => 'Acerca de ${Constants.appName}', + ), + ); + }, + ), + centerTitle: true, + ); + } + + Drawer _buildDrawer(BuildContext context) { + return Drawer( + child: Column( + children: [ + Expanded( + child: BlocBuilder( + builder: (_, state) { + return ListView( + children: [ + DrawerHeader( + child: Image.asset( + 'assets/images/logo-uh.png', + color: Theme.of(context).primaryColor, + ), + ), + ...state.when>( + loading: () => [ + ListTile( + leading: const GestionUhLoadingIndicator(), + title: Text( + 'Cargando ...', + style: Theme.of(context).textTheme.subtitle2, + ), + ), + ], + error: (error) => [ + ListTile( + leading: const Icon(Icons.error), + title: Text( + 'Error', + style: Theme.of(context).textTheme.subtitle2, + ), + ), + ], + profile: (p, x) => _getDrawerItems(context, p, x), + quota: (p, x) => _getDrawerItems(context, p, x), + mailQuota: (p, x) => _getDrawerItems(context, p, x), + resetPassword: (p, x) => _getDrawerItems(context, p, x), + aboutUs: (p, x) => _getDrawerItems(context, p, x), + logout: () => [ + ListTile( + leading: const GestionUhLoadingIndicator(), + title: Text( + 'Cerrando Sesión ...', + style: Theme.of(context).textTheme.subtitle2, + ), + ), + ], + ), + ], + ); + }, + ), + ), + const Align( + alignment: Alignment.bottomCenter, + child: GestionUHBottomSheet(), + ), + ], + ), + ); + } + + Widget _buildBody(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + return state.map( + loading: (state) { + return const Center( + child: GestionUhLoadingIndicator(), + ); + }, + error: (state) { + return Center( + child: Container( + margin: const EdgeInsets.all(20), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(state.message), + const SizedBox(height: 20), + GestionUhDefaultButton( + text: 'Reintentar', + onPressed: () { + context + .read() + .add(const HomeEvent.loadProfile()); + }, + ), + ], + ), + ), + ); + }, + logout: (state) { + return const Center( + child: GestionUhLoadingIndicator(), + ); + }, + profile: (state) { + return BlocProvider( + create: (_) => GetIt.I()..add(ProfileInitialized()), + child: const ProfilePage(), + ); + }, + quota: (state) { + return BlocProvider( + create: (_) => GetIt.I()..add(QuotaInitialized()), + child: const QuotaPage(), + ); + }, + mailQuota: (state) { + return BlocProvider( + create: (_) => + GetIt.I()..add(const MailQuotaEvent.quotaRequested()), + child: const MailQuotaPage(), + ); + }, + resetPassword: (state) { + return BlocProvider( + create: (_) => GetIt.I(), + child: const ResetPasswordPage(), + ); + }, + aboutUs: (state) { + return const AboutInformationPage(); + }, + ); + }, + ); + } + + List _getDrawerItems( + BuildContext context, + UserData profile, + List items, + ) { + return items.map((e) => _getDrawerItem(context, profile, e)).toList(); + } + + Widget _getDrawerItem( + BuildContext context, + UserData profile, + HomeItemEnum item, + ) { + switch (item) { + case HomeItemEnum.Separator: + return const Divider(); + case HomeItemEnum.Profile: + return _buildDrawerItem( + context: context, + text: 'Perfil', + icon: Icons.person, + onTap: () { + Navigator.of(context).pop(); + context.read().add(HomeEvent.goToProfile(profile)); + }, + ); + case HomeItemEnum.Quota: + return _buildDrawerItem( + context: context, + text: 'Mi Cuota', + icon: Icons.data_usage, + onTap: () { + Navigator.of(context).pop(); + context.read().add(HomeEvent.goToQuota(profile)); + }, + ); + case HomeItemEnum.MailQuota: + return _buildDrawerItem( + context: context, + text: 'Correo', + icon: Icons.mail, + onTap: () { + Navigator.of(context).pop(); + context.read().add(HomeEvent.goToMailQuota(profile)); + }, + ); + case HomeItemEnum.ResetPassword: + return _buildDrawerItem( + context: context, + text: 'Cambiar Contraseña', + icon: Icons.security_rounded, + onTap: () { + Navigator.of(context).pop(); + context.read().add(HomeEvent.goToResetPassword(profile)); + }, + ); + case HomeItemEnum.Logout: + return _buildDrawerItem( + context: context, + text: 'Cerrar Sesión', + icon: Icons.logout, + onTap: () async { + Navigator.of(context).pop(); + final option = await showDialog( + context: context, + builder: (context) { + return AlertDialog( + content: const Text('¿Está seguro que desea cerrar sesión?'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(true); + }, + child: const Text('Si'), + ), + TextButton( + onPressed: () async { + Navigator.of(context).pop(false); + }, + child: const Text('No'), + ), + ], + ); + }, + ); + if (option ?? false) { + context.read().add(const HomeEvent.logout()); + } + }, + ); + case HomeItemEnum.AboutUs: + return _buildDrawerItem( + context: context, + text: 'Acerca de', + icon: Icons.info_outline_rounded, + onTap: () { + Navigator.of(context).pop(); + context.read().add(HomeEvent.goToAboutUs(profile)); + }, + ); + } + } + + Widget _buildDrawerItem({ + required BuildContext context, + required String text, + IconData? icon, + void Function()? onTap, + }) { + return ListTile( + leading: Icon(icon), + title: Text( + text, + style: Theme.of(context).textTheme.subtitle2, + ), + onTap: onTap, + ); + } +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/about_page.dart b/lib/src/presentation/pages/home_page/sub_pages/about_page.dart new file mode 100644 index 0000000..3cc4536 --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/about_page.dart @@ -0,0 +1,172 @@ +import 'package:flutter/material.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +import 'package:responsive_builder/responsive_builder.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class AboutInformationPage extends StatelessWidget { + const AboutInformationPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scrollbar( + child: SingleChildScrollView( + child: Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const SizedBox( + height: 20, + ), + Center( + child: Image.asset( + 'assets/images/logo-uh.png', + color: Theme.of(context).primaryColor, + ), + ), + const SizedBox( + height: 20, + ), + Text( + About.shortDescription, + style: Theme.of(context) + .textTheme + .headline6! + .copyWith(fontSize: 15, color: Colors.black38), + ), + const SizedBox( + height: 50, + ), + Text( + 'Equipo de desarrollo:', + style: Theme.of(context).textTheme.headline5!.copyWith(), + ), + const SizedBox( + height: 30, + ), + Column( + children: Developers.teams.keys + .map((key) => ExpansionTile( + title: Text(key), + children: Developers.teams[key]! + .map((e) => ListTile( + title: Text( + e.name, + style: Theme.of(context) + .textTheme + .headline6! + .copyWith(fontSize: 14), + ), + subtitle: Text( + e.role, + style: Theme.of(context) + .textTheme + .bodyText1! + .copyWith(fontSize: 12), + ), + onTap: e.link == null + ? null + : () async { + if (await canLaunch(e.link!)) { + await launch(e.link!); + } else { + FlashHelper.errorBar( + context, + message: + 'No puede acceder a ${e.link}', + ); + } + }, + trailing: e.link != null + ? const Icon(Icons.link_off_outlined) + : null, + )) + .toList(), + )) + .toList(), + ), + const SizedBox(height: 50), + Text( + 'Nodo Central de Red - UH', + style: Theme.of(context).textTheme.headline6!.copyWith(), + ), + const SizedBox(height: 10), + Text( + 'MATCOM - UH', + style: Theme.of(context).textTheme.headline6!.copyWith(), + ), + const SizedBox(height: 10), + Text( + 'GRS - UH', + style: Theme.of(context).textTheme.headline6!.copyWith(), + ), + GestureDetector( + onTap: () async { + const url = + 'https://raw.githubusercontent.com/covid19cuba/covid19cuba-app/master/LICENSE'; + if (await canLaunch(url)) { + await launch(url); + } else { + FlashHelper.errorBar( + context, + message: 'No puede acceder a $url', + ); + } + }, + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Copyright 2021', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.subtitle2, + ), + Container( + padding: const EdgeInsets.all(2), + ), + Icon( + Icons.copyright, + color: Theme.of(context).textTheme.subtitle2!.color, + ), + Container( + padding: const EdgeInsets.all(2), + ), + Text( + 'GPL-3.0', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.subtitle2, + ), + ], + ), + ), + ) + ], + ), + ), + ), + ), + ); + } +} + +class DeveloperInfo { + final String? name; + final String? role; + final String? link; + + const DeveloperInfo({ + this.name, + this.role, + this.link, + }); +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/mail_quotas_page.dart b/lib/src/presentation/pages/home_page/sub_pages/mail_quotas_page.dart new file mode 100644 index 0000000..11d5867 --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/mail_quotas_page.dart @@ -0,0 +1,124 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/data/models/mail_quota.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:responsive_builder/responsive_builder.dart'; + +class MailQuotaPage extends StatefulWidget { + const MailQuotaPage({Key? key}) : super(key: key); + + @override + _MailQuotaPageState createState() => _MailQuotaPageState(); +} + +class _MailQuotaPageState extends State { + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + return state.maybeWhen( + loadFailure: (String error) => _buildFailurePage(context, error), + loadSuccess: (MailQuota quota) => _buildQuotaPage(context, quota), + orElse: () => _buildLoadingIndicator(context), + ); + }, + ); + } + + Widget _buildQuotaPage(BuildContext context, MailQuota quota) { + return RefreshIndicator( + onRefresh: () async { + context + .read() + .add(const MailQuotaEvent.quotaRequested()); + }, + child: Scrollbar( + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: MailQuotaGraph( + quota: quota, + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildFailurePage(BuildContext context, String error) { + return Scrollbar( + child: ListView( + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(error), + Padding( + padding: const EdgeInsets.all(5), + child: GestionUhDefaultButton( + text: 'Reintentar', + onPressed: () { + context.read().add( + const MailQuotaEvent.quotaRequested(), + ); + }, + ), + ), + ], + ), + ), + ), + ], + ), + ); + } + + Widget _buildLoadingIndicator(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + GestionUhLoadingIndicator(), + ], + ), + ); + } +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/profile_page.dart b/lib/src/presentation/pages/home_page/sub_pages/profile_page.dart new file mode 100644 index 0000000..b5fc869 --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/profile_page.dart @@ -0,0 +1,230 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:responsive_builder/responsive_builder.dart'; + +class ProfilePage extends StatefulWidget { + const ProfilePage({Key? key}) : super(key: key); + + @override + _ProfilePageState createState() => _ProfilePageState(); +} + +class _ProfilePageState extends State { + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + if (state is ProfileLoadedSuccess) { + return RefreshIndicator( + onRefresh: () async { + context.read().add(ProfileInitialized()); + }, + child: Scrollbar( + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if ((state.profile.name ?? '').isNotEmpty) + buildProfileField( + title: 'Nombre', + body: state.profile.name ?? '', + ), + if ((state.profile.email ?? '').isNotEmpty) + buildProfileField( + title: 'Correo', + body: state.profile.email ?? '', + ), + if ((state.profile.careerName ?? '').isNotEmpty) + buildProfileField( + title: 'Carrera', + body: state.profile.careerName ?? '', + ), + if ((state.profile.position ?? '').isNotEmpty) + buildProfileField( + title: 'Ocupación', + body: state.profile.position ?? '', + ), + if ((state.profile.objectClass ?? '').isNotEmpty) + buildProfileField( + title: 'Clase', + body: state.profile.objectClass ?? '', + ), + buildAccessFields( + mail: state.profile.hasEmail ?? false, + cloud: state.profile.hasCloud ?? false, + internet: state.profile.hasInternet ?? false, + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + if (state is ProfileLoadedFailure) { + return Scrollbar( + child: ListView( + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(state.error), + Padding( + padding: const EdgeInsets.all(5), + child: GestionUhDefaultButton( + text: 'Reintentar', + onPressed: () { + context + .read() + .add(ProfileInitialized()); + }, + ), + ), + ], + ), + ), + ), + ], + ), + ); + } + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + GestionUhLoadingIndicator(), + ], + ), + ); + }, + ); + } + + Widget buildProfileField({ + required String title, + required String body, + }) { + return Container( + padding: const EdgeInsets.symmetric( + vertical: 5, + horizontal: 10, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title), + const SizedBox( + height: 3, + ), + Text( + body, + style: const TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ); + } + + Widget buildAccessFields({ + required bool mail, + required bool cloud, + required bool internet, + }) { + return Container( + padding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 10, + ), + child: Column( + children: [ + buildToogleFiled( + icon: Icons.mail, + text: 'Acceso a Correo', + value: mail, + ), + const SizedBox( + height: 5, + ), + buildToogleFiled( + icon: Icons.cloud, + text: 'Acceso a Nube', + value: cloud, + ), + const SizedBox( + height: 5, + ), + buildToogleFiled( + icon: Icons.wifi, + text: 'Acceso a Internet', + value: internet, + ), + ], + ), + ); + } + + Widget buildToogleFiled({ + required IconData icon, + required String text, + required bool value, + }) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + text, + style: const TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ), + Icon( + icon, + color: value ? Colors.green : Colors.red, + ), + ], + ); + } +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/quota_page.dart b/lib/src/presentation/pages/home_page/sub_pages/quota_page.dart new file mode 100644 index 0000000..1f00f34 --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/quota_page.dart @@ -0,0 +1,111 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:responsive_builder/responsive_builder.dart'; + +class QuotaPage extends StatefulWidget { + const QuotaPage({Key? key}) : super(key: key); + + @override + _QuotaPageState createState() => _QuotaPageState(); +} + +class _QuotaPageState extends State { + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) {}, + builder: (context, state) { + if (state is QuotaLoadedSuccess) { + return RefreshIndicator( + onRefresh: () async { + context.read().add(QuotaInitialized()); + }, + child: Scrollbar( + child: ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: QuotaGraph( + quota: state.quota, + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + if (state is QuotaLoadedFailure) { + return Scrollbar( + child: ListView( + children: [ + Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(state.error), + Padding( + padding: const EdgeInsets.all(5), + child: GestionUhDefaultButton( + text: 'Reintentar', + onPressed: () { + context.read().add( + QuotaInitialized(), + ); + }, + ), + ), + ], + ), + ), + ), + ], + ), + ); + } + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + GestionUhLoadingIndicator(), + ], + ), + ); + }, + ); + } +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/reset_password_page.dart b/lib/src/presentation/pages/home_page/sub_pages/reset_password_page.dart new file mode 100644 index 0000000..9cc0bff --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/reset_password_page.dart @@ -0,0 +1,169 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/validators.dart'; +import 'package:responsive_builder/responsive_builder.dart'; + +class ResetPasswordPage extends StatefulWidget { + const ResetPasswordPage({Key? key}) : super(key: key); + + @override + _ResetPasswordPageState createState() => _ResetPasswordPageState(); +} + +class _ResetPasswordPageState extends State { + final _passwordCurrentController = TextEditingController(); + final _passwordFirstController = TextEditingController(); + final _passwordSecondController = TextEditingController(); + final _formPasswordKey = GlobalKey(); + + @override + void dispose() { + _passwordCurrentController.dispose(); + _passwordFirstController.dispose(); + _passwordSecondController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BlocConsumer( + listener: (context, state) { + state.maybeWhen( + success: () { + FlashHelper.successBar( + context, + message: 'La contraseña ha sido actualizada correctamente.', + ); + }, + failure: (error) => FlashHelper.errorBar( + context, + message: error, + ), + orElse: () {}, + ); + }, + builder: (context, state) { + return SingleChildScrollView( + child: Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, bottom: 9, left: 18, right: 18), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + // Hints Area + Padding( + padding: const EdgeInsets.symmetric(horizontal: 5.0), + child: RichText( + text: TextSpan( + style: Theme.of(context) + .textTheme + .bodyText1! + .copyWith(height: 1.4), + children: [ + TextSpan( + text: 'Su nueva contraseña debe tener:\n', + style: Theme.of(context).textTheme.headline6, + ), + ...const [ + '(1) Más de 8 caracteres.', + '(2) Al menos una minúscula.', + '(3) Al menos una mayúscula.', + '(4) Al menos un caracter especial, Ej. !\$@+.', + '(5) Al menos un número.', + ].map((e) => TextSpan(text: '$e\n')), + ]), + ), + ), + + // Password inputs + Form( + key: _formPasswordKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + // Current password input + Padding( + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: GestionUhDefaultTextField( + labelText: 'Contraseña Actual', + hintText: '********', + controller: _passwordCurrentController, + validator: currentPasswordValidator, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.visiblePassword, + ), + ), + const SizedBox( + height: 30, + child: Divider( + color: Colors.black54, + )), + Padding( + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: GestionUhDefaultTextField( + labelText: 'Contraseña Nueva*', + hintText: '********', + controller: _passwordFirstController, + validator: safetyPasswordValidator, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.visiblePassword, + ), + ), + + Padding( + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: GestionUhDefaultTextField( + labelText: 'Repetir Contraseña*', + hintText: '********', + controller: _passwordSecondController, + validator: safetyPasswordValidator, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.visiblePassword, + ), + ), + ], + ), + ), + const SizedBox(height: 25), + GestionUhDefaultButton( + text: 'Actualizar Contraseña', + onPressed: state.maybeWhen( + inProgress: () => null, + orElse: () { + return () => _resetPassword(context); + }, + ), + ), + const SizedBox(height: 30) + ], + ), + ), + ), + ); + }, + ); + } + + void _resetPassword(BuildContext context) { + if (_formPasswordKey.currentState!.validate()) { + final String currentPassword = _passwordCurrentController.text; + final String passwordFirst = _passwordFirstController.text; + final String passwordSecond = _passwordSecondController.text; + context.read().add( + ResetPasswordEvent.resetPasswordAttempted( + currentPassword: currentPassword, + passwordFirst: passwordFirst, + passwordSecond: passwordSecond, + ), + ); + } + } +} diff --git a/lib/src/presentation/pages/home_page/sub_pages/sub_pages.dart b/lib/src/presentation/pages/home_page/sub_pages/sub_pages.dart new file mode 100644 index 0000000..7486939 --- /dev/null +++ b/lib/src/presentation/pages/home_page/sub_pages/sub_pages.dart @@ -0,0 +1,5 @@ +export 'about_page.dart'; +export 'mail_quotas_page.dart'; +export 'profile_page.dart'; +export 'quota_page.dart'; +export 'reset_password_page.dart'; diff --git a/lib/src/presentation/pages/login_page.dart b/lib/src/presentation/pages/login_page.dart index bbdeb4c..c9d81f3 100644 --- a/lib/src/presentation/pages/login_page.dart +++ b/lib/src/presentation/pages/login_page.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/deps_injector.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; -import 'package:gestionuh/src/presentation/widgets/flash_helper.dart'; -import 'package:gestionuh/src/utils/constants/routes.dart'; +import 'package:gestionuh/src/data/local/local_storage.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +import 'package:gestionuh/src/utils/validators.dart'; +import 'package:get_it/get_it.dart'; +import 'package:responsive_builder/responsive_builder.dart'; class LoginPage extends StatefulWidget { const LoginPage({Key? key}) : super(key: key); @@ -16,18 +17,21 @@ class LoginPage extends StatefulWidget { } class _LoginPageState extends State { - final _usernameController = TextEditingController(); + final _userNameController = TextEditingController(); final _passwordController = TextEditingController(); bool _rememberMe = false; + final _formLoginKey = GlobalKey(); void _loginAction(BuildContext context) { - context.read().add( - LoginAttempted( - username: _usernameController.text, - password: _passwordController.text, - rememberMe: _rememberMe, - ), - ); + if (_formLoginKey.currentState?.validate() ?? false) { + context.read().add( + LoginEvent.loginAttempted( + userName: _userNameController.text, + password: _passwordController.text, + rememberMe: _rememberMe, + ), + ); + } } void _recoverAction(BuildContext context) { @@ -40,78 +44,102 @@ class _LoginPageState extends State { @override void dispose() { - _usernameController.dispose(); + _userNameController.dispose(); _passwordController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { - final authRepo = di(); + final authRepo = GetIt.I(); return Scaffold( appBar: AppBar( - title: const Text('Iniciar Sesión'), + title: const Text(Constants.appName), centerTitle: true, ), bottomSheet: const GestionUHBottomSheet(), body: BlocConsumer( listener: (context, state) { if (authRepo.logged) { - Navigator.of(context).pushReplacementNamed(PROFILE_ROUTE_NAME); - } - if (state is LoginAttemptInitial) { - FlashHelper.errorBar(context, message: state.error); + Navigator.of(context).pushReplacementNamed(HOME_ROUTE_NAME); } + state.maybeWhen( + failure: (error) => FlashHelper.errorBar(context, message: error), + orElse: () {}, + ); }, builder: (context, state) { - if (state is LoginAttemptInitial) { - return SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox( - height: 10, - ), - Image.asset( - 'assets/images/splash.png', - ), - const SizedBox( - height: 40, - ), - SizedBox( - height: 40, - child: Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - flex: 7, - child: GestionUhDefaultTextField( - labelText: '\t\tUsuario', - controller: _usernameController, - ), + return state.maybeWhen( + inProgress: () => _buildLoadingIndicator(context), + orElse: () => _buildLoginForm(context), + ); + }, + ), + ); + } + + Widget _buildLoginForm(BuildContext context) { + return Scrollbar( + child: SingleChildScrollView( + child: Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Form( + key: _formLoginKey, + autovalidateMode: AutovalidateMode.disabled, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + height: 10, + ), + Image.asset( + 'assets/images/splash.png', + ), + const SizedBox( + height: 40, + ), + SizedBox( + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + flex: 7, + child: GestionUhDefaultTextField( + labelText: 'Nombre de Usuario', + controller: _userNameController, + validator: userNameValidator, + autovalidateMode: AutovalidateMode.disabled, ), - ], - ), - ), - const SizedBox( - height: 10, - ), - GestionUhDefaultTextField( - labelText: '\t\tContraseña', - controller: _passwordController, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - const SizedBox( - height: 20, + ), + ], ), + ), + const SizedBox( + height: 10, + ), + GestionUhDefaultTextField( + labelText: 'Contraseña', + controller: _passwordController, + autovalidateMode: AutovalidateMode.disabled, + validator: currentPasswordValidator, + keyboardType: TextInputType.visiblePassword, + ), + const SizedBox( + height: 20, + ), + if (GetIt.I().isSecureStorageAvailable) GestureDetector( onTap: () => setState(() => _rememberMe = !_rememberMe), child: Container( @@ -142,44 +170,46 @@ class _LoginPageState extends State { ), ), ), - const SizedBox( - height: 5, - ), - GestionUhDefaultButton( - text: 'Iniciar Sesión', - onPressed: () => _loginAction(context), - ), - const SizedBox( - height: 5, - ), - GestionUhDefaultButton( - text: 'Recuperar Contraseña', - onPressed: () => _recoverAction(context), - ), - const SizedBox( - height: 5, - ), - GestionUhDefaultButton( - text: 'Registrarse', - onPressed: () => _registerAction(context), - ), - const SizedBox( - height: 40, - ), - ], - ), + const SizedBox( + height: 5, + ), + GestionUhDefaultButton( + text: 'Iniciar Sesión', + onPressed: () => _loginAction(context), + ), + const SizedBox( + height: 5, + ), + GestionUhDefaultButton( + text: 'Recuperar Contraseña', + onPressed: () => _recoverAction(context), + ), + const SizedBox( + height: 5, + ), + GestionUhDefaultButton( + text: 'Registrarse', + onPressed: () => _registerAction(context), + ), + const SizedBox( + height: 30, + ), + ], ), - ); - } - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - GestionUhLoadingIndicator(), - ], ), - ); - }, + ), + ), + ), + ); + } + + Widget _buildLoadingIndicator(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + GestionUhLoadingIndicator(), + ], ), ); } diff --git a/lib/src/presentation/pages/mail_quotas_page.dart b/lib/src/presentation/pages/mail_quotas_page.dart deleted file mode 100644 index a54b113..0000000 --- a/lib/src/presentation/pages/mail_quotas_page.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; - -class MailQuotaPage extends StatefulWidget { - const MailQuotaPage({Key? key}) : super(key: key); - - @override - _MailQuotaPageState createState() => _MailQuotaPageState(); -} - -class _MailQuotaPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Correo'), - centerTitle: true, - ), - bottomSheet: const GestionUHBottomSheet(), - drawer: DefaultDrawer(), - body: BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - if (state is MailQuotaLoadedSuccess) { - return RefreshIndicator( - onRefresh: () async { - context.read().add(MailQuotaInitialized()); - }, - child: ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, - bottom: 9, - left: 18, - right: 18, - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: MailQuotaGraph( - quota: state.quota!, - ), - ), - ], - ), - ), - ], - ), - ); - } - if (state is MailQuotaLoadedFailure) { - return ListView( - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(state.error!), - Padding( - padding: const EdgeInsets.all(5), - child: GestionUhDefaultButton( - text: 'Reintentar', - onPressed: () { - context.read().add( - MailQuotaInitialized(), - ); - }, - ), - ), - ], - ), - ), - ], - ); - } - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - GestionUhLoadingIndicator(), - ], - ), - ); - }, - ), - ); - } -} diff --git a/lib/src/presentation/pages/pages.dart b/lib/src/presentation/pages/pages.dart new file mode 100644 index 0000000..4221e0d --- /dev/null +++ b/lib/src/presentation/pages/pages.dart @@ -0,0 +1,4 @@ +export 'home_page/home_page.dart'; +export 'login_page.dart'; +export 'recover_password_page.dart'; +export 'register_page.dart'; diff --git a/lib/src/presentation/pages/profile_page.dart b/lib/src/presentation/pages/profile_page.dart deleted file mode 100644 index 01fc82b..0000000 --- a/lib/src/presentation/pages/profile_page.dart +++ /dev/null @@ -1,215 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; - -class ProfilePage extends StatefulWidget { - const ProfilePage({Key? key}) : super(key: key); - - @override - _ProfilePageState createState() => _ProfilePageState(); -} - -class _ProfilePageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Perfil'), - centerTitle: true, - ), - bottomSheet: const GestionUHBottomSheet(), - drawer: DefaultDrawer(), - body: BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - if (state is ProfileLoadedSuccess) { - return RefreshIndicator( - onRefresh: () async { - context.read().add(ProfileInitialized()); - }, - child: ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - buildProfileField( - title: 'Nombre', - body: state.profile.name ?? '', - ), - buildProfileField( - title: 'Correo', - body: state.profile.email ?? '', - ), - buildProfileField( - title: 'Carrera', - body: state.profile.careerName ?? '', - ), - buildProfileField( - title: 'Ocupación', - body: state.profile.position ?? '', - ), - buildProfileField( - title: 'Clase', - body: state.profile.objectClass ?? '', - ), - buildAccessFields( - mail: state.profile.hasEmail ?? false, - cloud: state.profile.hasCloud ?? false, - internet: state.profile.hasInternet ?? false, - ), - ], - ), - ), - ], - ), - ); - } - if (state is ProfileLoadedFailure) { - return ListView( - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(state.error), - Padding( - padding: const EdgeInsets.all(5), - child: GestionUhDefaultButton( - text: 'Reintentar', - onPressed: () { - context.read().add( - ProfileInitialized(), - ); - }, - ), - ), - ], - ), - ), - ], - ); - } - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - GestionUhLoadingIndicator(), - ], - ), - ); - }, - ), - ); - } - - Widget buildProfileField({ - required String title, - required String body, - }) { - return Container( - padding: const EdgeInsets.symmetric( - vertical: 5, - horizontal: 10, - ), - child: Row( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(title), - const SizedBox( - height: 3, - ), - Text( - body, - style: const TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ], - ), - ); - } - - Widget buildAccessFields({ - required bool mail, - required bool cloud, - required bool internet, - }) { - return Container( - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 10, - ), - child: Column( - children: [ - buildToogleFiled( - icon: Icons.mail, - text: 'Acceso a Correo', - value: mail, - ), - const SizedBox( - height: 5, - ), - buildToogleFiled( - icon: Icons.cloud, - text: 'Acceso a Nube', - value: cloud, - ), - const SizedBox( - height: 5, - ), - buildToogleFiled( - icon: Icons.wifi, - text: 'Acceso a Internet', - value: internet, - ), - ], - ), - ); - } - - Widget buildToogleFiled({ - required IconData icon, - required String text, - required bool value, - }) { - return Row( - children: [ - SizedBox( - width: MediaQuery.of(context).size.width * 0.5, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - text, - style: const TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Icon( - icon, - color: value ? Colors.green : Colors.red, - ), - ], - ), - ), - ], - ); - } -} diff --git a/lib/src/presentation/pages/quota_page.dart b/lib/src/presentation/pages/quota_page.dart deleted file mode 100644 index aed4694..0000000 --- a/lib/src/presentation/pages/quota_page.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; - -class QuotaPage extends StatefulWidget { - const QuotaPage({Key? key}) : super(key: key); - - @override - _QuotaPageState createState() => _QuotaPageState(); -} - -class _QuotaPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Mi Cuota'), - centerTitle: true, - ), - bottomSheet: const GestionUHBottomSheet(), - drawer: DefaultDrawer(), - body: BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - if (state is QuotaLoadedSuccess) { - return RefreshIndicator( - onRefresh: () async { - context.read().add(QuotaInitialized()); - }, - child: ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: QuotaGraph( - quota: state.quota, - ), - ), - ], - ), - ), - ], - ), - ); - } - if (state is QuotaLoadedFailure) { - return ListView( - children: [ - Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text(state.error), - Padding( - padding: const EdgeInsets.all(5), - child: GestionUhDefaultButton( - text: 'Reintentar', - onPressed: () { - context.read().add( - QuotaInitialized(), - ); - }, - ), - ), - ], - ), - ), - ], - ); - } - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - GestionUhLoadingIndicator(), - ], - ), - ); - }, - ), - ); - } -} diff --git a/lib/src/presentation/pages/recover_password_page.dart b/lib/src/presentation/pages/recover_password_page.dart index 185da32..03b137b 100644 --- a/lib/src/presentation/pages/recover_password_page.dart +++ b/lib/src/presentation/pages/recover_password_page.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/flash_helper.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; import 'package:gestionuh/src/utils/validators.dart'; +import 'package:responsive_builder/responsive_builder.dart'; class RecoverPasswordPage extends StatelessWidget { final _formKey = GlobalKey(); @@ -11,208 +11,267 @@ class RecoverPasswordPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('Recuperar Contraseña'), - centerTitle: true, + appBar: AppBar( + title: const Text('Recuperar Contraseña'), + centerTitle: true, + ), + bottomSheet: const GestionUHBottomSheet(), + body: Scrollbar( + child: Center( + child: SizedBox( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + child: BlocConsumer( + listener: (context, state) { + state.maybeMap( + ciError: (state) { + FlashHelper.errorBar(context, message: state.error); + }, + questionsError: (state) { + FlashHelper.errorBar(context, message: state.error); + }, + orElse: () {}, + ); + }, + builder: (context, state) { + return state.when( + initial: (ci) => _buildInitial(context, ci, false), + ciLoading: (ci) => _buildInitial(context, ci, true), + ciError: (ci, _) => _buildInitial(context, ci, false), + questions: (ci, questions, answers, password) { + return _buildQuestions( + context, + ci, + questions, + answers, + password, + false, + ); + }, + questionsLoading: (ci, questions, answers, password) { + return _buildQuestions( + context, + ci, + questions, + answers, + password, + true, + ); + }, + questionsError: (ci, questions, answers, password, _) { + return _buildQuestions( + context, + ci, + questions, + answers, + password, + false, + ); + }, + success: (userId) => _buildSuccess(context, userId), + ); + }, + ), + ), ), - bottomSheet: const GestionUHBottomSheet(), - body: BlocConsumer( - listener: (context, state) { - if (state is RecoverPasswordError) { - FlashHelper.errorBar(context, message: state.error); - } - }, - builder: (context, state) { - if (state is RecoverPasswordInitial) { - return Form( - key: _formKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Opacity( - opacity: state is RecoverPasswordCILoading ? 1 : 0, - child: const LinearProgressIndicator(), - ), - Container( - padding: const EdgeInsets.only( - top: 30, - bottom: 9, - left: 18, - right: 18, - ), - child: Column( - children: [ - Container( - padding: const EdgeInsets.symmetric( - vertical: 8.0, - ), - child: GestionUhDefaultTextField( - labelText: '\t\tNúmero de Carnet de Identidad*', - controller: state.ci, - validator: identityNumberCIValidator, - autovalidateMode: AutovalidateMode.disabled, - keyboardType: TextInputType.text, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - const SizedBox( - height: 25, + ), + ); + } + + Widget _buildInitial( + BuildContext context, + TextEditingController ci, + bool loading, + ) { + return Form( + key: _formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Opacity( + opacity: loading ? 1 : 0, + child: const GestionUhLoadingIndicator(), + ), + Container( + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + children: [ + Container( + padding: const EdgeInsets.symmetric( + vertical: 8.0, + ), + child: GestionUhDefaultTextField( + labelText: 'Número de Carnet de Identidad*', + controller: ci, + validator: identityNumberCIValidator, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.text, + ), + ), + const SizedBox( + height: 25, + ), + GestionUhDefaultButton( + text: 'Continuar', + onPressed: () { + if (loading || !_formKey.currentState!.validate()) { + return; + } + context + .read() + .add(RecoverPasswordEvent.ciSubmit(ci)); + }, + ), + ], + ), + ) + ], + ), + ); + } + + Widget _buildQuestions( + BuildContext context, + String ci, + List questions, + List answers, + TextEditingController password, + bool loading, + ) { + return SingleChildScrollView( + child: Form( + key: _formKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Opacity( + opacity: loading ? 1 : 0, + child: const LinearProgressIndicator(), + ), + Container( + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Column( + children: [ + for (var i = 0; i < questions.length; ++i) + Column( + children: [ + Text(questions[i]), + Container( + padding: const EdgeInsets.symmetric( + vertical: 8.0, ), - GestionUhDefaultButton( - text: 'Continuar', - onPressed: () { - if (state is RecoverPasswordCILoading || - !_formKey.currentState!.validate()) { - return; + child: GestionUhDefaultTextField( + controller: answers[i], + validator: (value) { + if (value == null || value.isEmpty) { + return 'La respuesta es necesaria.'; } - context - .read() - .add(RecoverPasswordCISubmit(state: state)); + return null; }, + autovalidateMode: AutovalidateMode.disabled, + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(5), + bottomLeft: Radius.circular(5), + ), ), - ], - ), - ) - ], - ), - ); - } - if (state is RecoverPasswordQuestions) { - return SingleChildScrollView( - child: Form( - key: _formKey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Opacity( - opacity: - state is RecoverPasswordQuestionsLoading ? 1 : 0, - child: const LinearProgressIndicator(), - ), - Container( - padding: const EdgeInsets.only( - top: 30, - bottom: 9, - left: 18, - right: 18, ), - child: Column( - children: [ - for (var i = 0; i < state.questions.length; ++i) - Column( - children: [ - Text(state.questions[i]), - Container( - padding: const EdgeInsets.symmetric( - vertical: 8.0, - ), - child: GestionUhDefaultTextField( - controller: state.answers[i], - validator: (value) { - if (value == null || value.isEmpty) { - return 'La respuesta es necesaria.'; - } - return null; - }, - autovalidateMode: - AutovalidateMode.disabled, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - const SizedBox( - height: 10, - ), - ], - ), - Padding( - padding: - const EdgeInsets.symmetric(vertical: 8.0), - child: GestionUhDefaultTextField( - labelText: '\t\tContraseña*', - controller: state.password, - validator: safetyPasswordValidator, - autovalidateMode: AutovalidateMode.disabled, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - const SizedBox( - height: 10, - ), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 8.0, - ), - child: GestionUhDefaultTextField( - labelText: '\t\tRepetir Contraseña*', - validator: (value) { - if (value != state.password.text) { - return 'Las contraseñas deben coincidir'; - } - return null; - }, - autovalidateMode: AutovalidateMode.disabled, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - const SizedBox( - height: 25, - ), - GestionUhDefaultButton( - text: 'Continuar', - onPressed: () { - if (state is RecoverPasswordCILoading || - !_formKey.currentState!.validate()) { - return; - } - context.read().add( - RecoverPasswordFinalSubmit(state: state)); - }, - ), - ], + const SizedBox( + height: 10, ), - ) - ], + ], + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: GestionUhDefaultTextField( + labelText: 'Contraseña*', + controller: password, + validator: safetyPasswordValidator, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.visiblePassword, + ), ), - ), - ); - } - if (state is RecoverPasswordSuccess) { - return Container( - margin: const EdgeInsets.all(30), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Se ha cambiado correctamente la contraseña ' - 'de la cuenta "${state.userId}".', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.subtitle1, + const SizedBox( + height: 10, + ), + Padding( + padding: const EdgeInsets.symmetric( + vertical: 8.0, ), - const SizedBox(height: 30), - GestionUhDefaultButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Ok'), + child: GestionUhDefaultTextField( + labelText: 'Repetir Contraseña*', + validator: (value) { + if (value != password.text) { + return 'Las contraseñas deben coincidir'; + } + return null; + }, + autovalidateMode: AutovalidateMode.disabled, + keyboardType: TextInputType.visiblePassword, ), - ], - ), - ); - } - return Container(); - }, - )); + ), + const SizedBox( + height: 25, + ), + GestionUhDefaultButton( + text: 'Continuar', + onPressed: () { + if (loading || !_formKey.currentState!.validate()) { + return; + } + context + .read() + .add(RecoverPasswordEvent.finalSubmit( + ci, + questions, + answers, + password, + )); + }, + ), + ], + ), + ), + const SizedBox( + height: 30, + ), + ], + ), + ), + ); + } + + Widget _buildSuccess(BuildContext context, String userId) { + return Container( + margin: const EdgeInsets.all(30), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Se ha cambiado correctamente la contraseña ' + 'de la cuenta "$userId".', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.subtitle1, + ), + const SizedBox(height: 30), + GestionUhDefaultButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Ok'), + ), + ], + ), + ); } } diff --git a/lib/src/presentation/pages/register_page.dart b/lib/src/presentation/pages/register_page.dart index 4b1f967..25ce226 100644 --- a/lib/src/presentation/pages/register_page.dart +++ b/lib/src/presentation/pages/register_page.dart @@ -1,13 +1,13 @@ import 'package:collection/collection.dart' show IterableExtension; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; -import 'package:gestionuh/src/presentation/widgets/flash_helper.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; import 'package:gestionuh/src/utils/pair.dart'; import 'package:gestionuh/src/utils/validators.dart'; +import 'package:responsive_builder/responsive_builder.dart'; class RegisterPage extends StatefulWidget { const RegisterPage({Key? key}) : super(key: key); @@ -19,11 +19,13 @@ class RegisterPage extends StatefulWidget { class _RegisterPageState extends State { late List> questions; late List questionsTaken; + late bool termsAccepted; late List answersTextControllers; - TextEditingController ciController = TextEditingController(); - TextEditingController passwordFirstController = TextEditingController(); - TextEditingController passwordSecondController = TextEditingController(); + final TextEditingController ciController = TextEditingController(); + final TextEditingController passwordFirstController = TextEditingController(); + final TextEditingController passwordSecondController = + TextEditingController(); final _formKey = GlobalKey(); @override @@ -40,6 +42,7 @@ class _RegisterPageState extends State { @override void initState() { super.initState(); + termsAccepted = false; questions = []; questionsTaken = []; answersTextControllers = List.generate( @@ -55,230 +58,255 @@ class _RegisterPageState extends State { ); if (qFree == null) return null; questionsTaken[qFree.second] = index; - answersTextControllers[index].clear(); + WidgetsBinding.instance!.addPostFrameCallback((_) { + answersTextControllers[index].clear(); + }); return qFree; } + Future _showTermsAndConditionsDialog() async { + final accepted = await FlashHelper.aceptDeclineDialog( + context, + ); + setState(() { + termsAccepted = accepted ?? false; + }); + } + void _onRegisterAction() { if (!(_formKey.currentState?.validate() ?? false)) return; - if (questionsTaken.where((element) => element != -1).length != - NUMBER_OF_SECURITY_QUESTIONS_NEEDED) return; + if (!termsAccepted || + questionsTaken.where((element) => element != -1).length != + NUMBER_OF_SECURITY_QUESTIONS_NEEDED) return; final _questions = questions.map((e) => questionsTaken[e.second] >= 0 ? e : null).toList(); _questions.removeWhere((element) => element == null); _questions.sort((e1, e2) => questionsTaken[e1!.second].compareTo(questionsTaken[e2!.second])); - context.read().add( - FormsEnteredRegister( - ci: ciController.text, - passwordFirst: passwordFirstController.text, - passwordSecond: passwordSecondController.text, - questions: _questions.map((e) => e!.first).toList(), - answers: answersTextControllers.map((e) => e.text).toList(), - ), - ); + context.read().add(RegisterEvent.formSubmitted( + ci: ciController.text, + passwordFirst: passwordFirstController.text, + passwordSecond: passwordSecondController.text, + questions: _questions.map((e) => e!.first).toList(), + answers: answersTextControllers.map((e) => e.text).toList(), + )); } @override Widget build(BuildContext context) { - final TextStyle headlineTextsTheme = Theme.of(context) - .textTheme - .headline6! - .copyWith(color: Theme.of(context).primaryColor, fontSize: 16); return Scaffold( appBar: AppBar( title: const Text('Registrarse'), centerTitle: true, ), - bottomSheet: const GestionUHBottomSheet(), body: BlocConsumer( listener: (context, state) async { - if (state is RegisterUserFailure) { - FlashHelper.errorBar(context, message: state.error); - } else if (state is LoadInitialDataFailure) { - Future.delayed( - const Duration(seconds: 2), - () => context - .read() - .add(QuestionsRequestedRegister()), - ); - } else if (state is RegisterUserSuccess) { - FlashHelper.infoBar(context, - message: 'El usuario fue registrado correctamente.'); - } + state.maybeWhen( + initialLoadFailure: (error) async { + await FlashHelper.errorBar(context, message: error); + Future.delayed( + const Duration(seconds: 1), + () => context + .read() + .add(const RegisterEvent.questionsRequested()), + ); + }, + registrationFailure: (error) { + FlashHelper.errorBar(context, message: error); + }, + registrationSuccess: (_) { + FlashHelper.successBar(context, + message: 'El usuario fue registrado correctamente.'); + }, + orElse: () {}, + ); }, builder: (context, state) { - if (state is LoadInitialDataSuccess && questions.isEmpty) { - int i = 0; - questions = state.questions - .map((e) => Pair(first: e, second: i++)) - .toList(); - questionsTaken = List.filled(questions.length, -1); - } - if (state is RegisterUserFailure || - state is LoadInitialDataSuccess || - state is LoadInitialDataInProgress || - state is LoadInitialDataFailure) { - return SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Form( - key: _formKey, - autovalidateMode: AutovalidateMode.disabled, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - 'Todos los campos son obligatorios.*', - style: Theme.of(context) - .textTheme - .headline6! - .copyWith(fontSize: 14, color: Colors.black45), - textAlign: TextAlign.center, - ), - const SizedBox( - height: 30, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Número de Carnet De Identidad', - style: headlineTextsTheme, - ), - GestionUhDefaultTextField( - hintText: '###########', - autovalidateMode: AutovalidateMode.disabled, - controller: ciController, - validator: identityNumberCIValidator, - keyboardType: TextInputType.number, - ), - ]), - const SizedBox( - height: 15, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Contraseña', - style: headlineTextsTheme, - ), - GestionUhDefaultTextField( - hintText: '********', - autovalidateMode: AutovalidateMode.disabled, - controller: passwordFirstController, - validator: safetyPasswordValidator, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ]), - const SizedBox( - height: 20, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Repetir Contraseña', - style: headlineTextsTheme, - ), - GestionUhDefaultTextField( - hintText: '********', - autovalidateMode: AutovalidateMode.disabled, - controller: passwordSecondController, - validator: safetyPasswordValidator, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ]), - const SizedBox( - height: 20, - ), - Text( - 'Introduzca respuesta para las preguntas de seguridad de su preferencia.', - style: Theme.of(context) - .textTheme - .headline6! - .copyWith(fontSize: 14, color: Colors.black45), - textAlign: TextAlign.center, - ), - Builder( - builder: (BuildContext context) { - final childrenQuest = []; - const length = NUMBER_OF_SECURITY_QUESTIONS_NEEDED; - for (int i = 0; i < length; i++) { - childrenQuest.add(buildQuestionZone(i)); - } - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: childrenQuest, - ); - }, - ), - const SizedBox(height: 10), - GestionUhDefaultButton( - text: 'Finalizar', - onPressed: _onRegisterAction, - ), - const SizedBox(height: 30), - ], - ), - ), - ), - ); - } else if (state is RegisterUserSuccess) { - return Container( - margin: const EdgeInsets.all(30), + return state.maybeWhen( + initialLoadSuccess: (List loadedQuestions) => + _buildRegisterFormPageAndLoadQuestion(context, loadedQuestions), + registrationSuccess: (String userEmail) => + _buildRegisterSuccessPage(context, userEmail), + orElse: () => _buildRegisterFormPage(context), + ); + }, + ), + ); + } + + Widget _buildRegisterFormPageAndLoadQuestion( + BuildContext context, + List loadedQuestions, + ) { + if (questions.isEmpty) { + int i = 0; + questions = + loadedQuestions.map((e) => Pair(first: e, second: i++)).toList(); + questionsTaken = List.filled(questions.length, -1); + } + return _buildRegisterFormPage(context); + } + + Widget _buildRegisterFormPage(BuildContext context) { + final TextStyle headlineTextsTheme = Theme.of(context) + .textTheme + .headline6! + .copyWith(color: Theme.of(context).primaryColor, fontSize: 16); + return Scrollbar( + child: SingleChildScrollView( + child: Center( + child: Container( + width: getValueForScreenType( + context: context, + mobile: MediaQuery.of(context).size.width, + tablet: MediaQuery.of(context).size.width * 0.5, + ), + padding: const EdgeInsets.only( + top: 30, + bottom: 9, + left: 18, + right: 18, + ), + child: Form( + key: _formKey, + autovalidateMode: AutovalidateMode.disabled, child: Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, children: [ - RichText( + const SizedBox( + height: 10, + ), + GestionUhDefaultTextField( + labelText: 'Número de Carnet De Identidad', + labelStyle: headlineTextsTheme, + hintText: '###########', + autovalidateMode: AutovalidateMode.disabled, + controller: ciController, + validator: identityNumberCIValidator, + keyboardType: TextInputType.number, + ), + const SizedBox( + height: 20, + ), + GestionUhDefaultTextField( + labelText: 'Contraseña', + labelStyle: headlineTextsTheme, + hintText: '********', + autovalidateMode: AutovalidateMode.disabled, + controller: passwordFirstController, + validator: safetyPasswordValidator, + keyboardType: TextInputType.visiblePassword, + ), + const SizedBox( + height: 15, + ), + GestionUhDefaultTextField( + labelText: 'Repetir Contraseña', + labelStyle: headlineTextsTheme, + hintText: '********', + autovalidateMode: AutovalidateMode.disabled, + controller: passwordSecondController, + validator: safetyPasswordValidator, + keyboardType: TextInputType.visiblePassword, + ), + const SizedBox(height: 60), + const Divider( + color: Colors.black54, + ), + const SizedBox(height: 10), + Text( + 'PREGUNTAS DE SEGURIDAD', + style: Theme.of(context).textTheme.headline6!.copyWith( + fontSize: 14, + color: Colors.black54, + fontWeight: FontWeight.bold), textAlign: TextAlign.center, - text: TextSpan( - style: Theme.of(context).textTheme.subtitle1, - children: [ - const TextSpan( - text: 'Se ha registrado correctamente ' - 'su correo es ', - ), - TextSpan( - text: '"${state.userEmail}"', - style: Theme.of(context) - .textTheme - .subtitle1 - ?.copyWith(color: Colors.red), - ), - const TextSpan( - text: ', anótelo de ser necesario ' - 'no se mostrará otra vez', - ), - ]), ), - const SizedBox(height: 30), + Builder( + builder: (BuildContext context) { + final childrenQuest = []; + const length = NUMBER_OF_SECURITY_QUESTIONS_NEEDED; + for (int i = 0; i < length; i++) { + final pairValue = questionsTaken.contains(i) + ? questions[questionsTaken.indexOf(i)] + : getFirstQuestionNotOccupeid(i); + childrenQuest.add(_buildQuestionZone(i, pairValue)); + } + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: childrenQuest, + ); + }, + ), + CheckboxListTile( + controlAffinity: ListTileControlAffinity.leading, + dense: true, + activeColor: Theme.of(context).primaryColor, + value: termsAccepted, + title: Text( + 'ACEPTO LOS TÉRMINOS Y CONDICIONES', + overflow: TextOverflow.fade, + softWrap: true, + style: Theme.of(context) + .textTheme + .subtitle2 + ?.copyWith(color: Theme.of(context).primaryColor), + ), + onChanged: (value) => _showTermsAndConditionsDialog()), + const SizedBox(height: 15), GestionUhDefaultButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Ok'), + text: 'Finalizar', + onPressed: termsAccepted ? _onRegisterAction : null, ), + const SizedBox(height: 30), ], ), - ); - } else { - return Container(); - } - }, + ), + ), + ), + ), + ); + } + + Widget _buildRegisterSuccessPage(BuildContext context, String userEmail) { + return Container( + margin: const EdgeInsets.all(30), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + RichText( + textAlign: TextAlign.center, + text: TextSpan( + style: Theme.of(context).textTheme.subtitle1, + children: [ + const TextSpan( + text: 'Se ha registrado correctamente ' + 'su correo es ', + ), + TextSpan( + text: '"$userEmail"', + style: Theme.of(context) + .textTheme + .subtitle1 + ?.copyWith(color: Colors.red), + ), + const TextSpan( + text: ', anótelo de ser necesario ' + 'no se mostrará otra vez', + ), + ]), + ), + const SizedBox(height: 30), + GestionUhDefaultButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Ok'), + ), + ], ), ); } - Widget buildQuestionZone(int index) { + Widget _buildQuestionZone(int index, Pair? valueSelected) { final TextStyle headlineTextsTheme = Theme.of(context) .textTheme .headline6! @@ -291,7 +319,7 @@ class _RegisterPageState extends State { children: [ DropdownButton( underline: Container(), - icon: const Icon(Icons.add_box_outlined), + icon: const Icon(Icons.arrow_drop_down), isExpanded: true, hint: Text( 'Seleccione una pregunta', @@ -308,16 +336,13 @@ class _RegisterPageState extends State { ), )) .toList(), - value: questionsTaken.contains(index) - ? questions[questionsTaken.indexOf(index)] - : getFirstQuestionNotOccupeid(index), + value: valueSelected, onChanged: (Pair? value) { setState(() { if (questionsTaken.contains(index)) { // clean text boxs final oldIndex = questionsTaken.indexOf(index); questionsTaken[oldIndex] = -1; - answersTextControllers[oldIndex].clear(); } questionsTaken[value!.second] = index; answersTextControllers[index].clear(); @@ -328,6 +353,7 @@ class _RegisterPageState extends State { GestionUhDefaultTextField( hintText: 'Respuesta No.${index + 1}', validator: answerValidator, + autovalidateMode: AutovalidateMode.disabled, controller: answersTextControllers[index], ) else diff --git a/lib/src/presentation/pages/reset_password_page.dart b/lib/src/presentation/pages/reset_password_page.dart deleted file mode 100644 index 26067f1..0000000 --- a/lib/src/presentation/pages/reset_password_page.dart +++ /dev/null @@ -1,162 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:gestionuh/src/presentation/blocs/reset_password_bloc/resetpassword_bloc.dart'; -import 'package:gestionuh/src/presentation/widgets.dart'; -import 'package:gestionuh/src/presentation/widgets/bottom_sheet.dart'; -import 'package:gestionuh/src/presentation/widgets/flash_helper.dart'; -import 'package:gestionuh/src/utils/validators.dart'; - -class ResetPasswordPage extends StatefulWidget { - const ResetPasswordPage({Key? key}) : super(key: key); - - @override - _ResetPasswordPageState createState() => _ResetPasswordPageState(); -} - -class _ResetPasswordPageState extends State { - final _passwordFirstController = TextEditingController(); - final _passwordSecondController = TextEditingController(); - final _formPasswordKey = GlobalKey(); - - @override - void dispose() { - _passwordFirstController.dispose(); - _passwordSecondController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Cambiar Contraseña'), - centerTitle: true, - ), - bottomSheet: const GestionUHBottomSheet(), - body: BlocConsumer( - listener: (context, state) { - if (state is ResetPasswordInitial) { - FlashHelper.errorBar(context, message: state.error); - } - if (state is ResetPasswordSuccess) { - FlashHelper.infoBar(context, - message: 'La contraseña ha sido actualizada correctamente.'); - } - }, - builder: (context, state) { - return SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.only( - top: 30, bottom: 9, left: 18, right: 18), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - // Hints Area - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 5.0, - vertical: 16.0, - ), - child: RichText( - text: TextSpan( - style: Theme.of(context) - .textTheme - .bodyText1! - .copyWith(height: 1.4), - children: [ - TextSpan( - text: 'Su nueva contraseña debe tener:\n', - style: Theme.of(context).textTheme.headline6, - ), - const TextSpan( - text: '(1) Más de 8 caracteres.\n', - ), - const TextSpan( - text: '(2) Al menos una minúscula.\n', - ), - const TextSpan( - text: '(3) Al menos una mayúscula.\n', - ), - const TextSpan( - text: - '(4) Al menos un caracter especial, Ej. !\$@+.\n', - ), - const TextSpan( - text: '(5) Al menos un número.\n', - ), - ]), - ), - ), - - // Password inputs - Form( - key: _formPasswordKey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: const EdgeInsets.symmetric(vertical: 8.0), - child: GestionUhDefaultTextField( - labelText: '\t\tContraseña*', - controller: _passwordFirstController, - validator: safetyPasswordValidator, - autovalidateMode: AutovalidateMode.disabled, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - const SizedBox( - height: 10, - ), - Padding( - padding: const EdgeInsets.symmetric(vertical: 8.0), - child: GestionUhDefaultTextField( - labelText: '\t\tRepetir Contraseña*', - controller: _passwordSecondController, - validator: safetyPasswordValidator, - autovalidateMode: AutovalidateMode.disabled, - keyboardType: TextInputType.visiblePassword, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(5), - bottomLeft: Radius.circular(5), - ), - ), - ), - ], - ), - ), - const SizedBox( - height: 25, - ), - GestionUhDefaultButton( - text: 'Actualizar Contraseña', - onPressed: state is ResetPasswordInProgress - ? null - : () => _resetPassword(context), - ), - ], - ), - ), - ); - }, - )); - } - - void _resetPassword(BuildContext context) { - if (_formPasswordKey.currentState!.validate()) { - final String passwordFirst = _passwordFirstController.text; - final String passwordSecond = _passwordSecondController.text; - log('Password 1 $passwordFirst'); - log('Password 2 $passwordSecond'); - context.read().add( - ResetPasswordAttempted( - passwordFirst: passwordFirst, passwordSecond: passwordSecond), - ); - } - } -} diff --git a/lib/src/presentation/theme.dart b/lib/src/presentation/theme.dart deleted file mode 100644 index d191ca4..0000000 --- a/lib/src/presentation/theme.dart +++ /dev/null @@ -1 +0,0 @@ -export 'theme/theme_data.dart'; diff --git a/lib/src/presentation/theme/theme.dart b/lib/src/presentation/theme/theme.dart new file mode 100644 index 0000000..58d9d63 --- /dev/null +++ b/lib/src/presentation/theme/theme.dart @@ -0,0 +1 @@ +export 'theme_data.dart'; diff --git a/lib/src/presentation/widgets.dart b/lib/src/presentation/widgets.dart deleted file mode 100644 index adabdb7..0000000 --- a/lib/src/presentation/widgets.dart +++ /dev/null @@ -1,7 +0,0 @@ -export 'widgets/bottom_sheet.dart'; -export 'widgets/buttons.dart'; -export 'widgets/drawers.dart'; -export 'widgets/loading_indicators.dart'; -export 'widgets/mail_quota_graph.dart'; -export 'widgets/quota_graph.dart'; -export 'widgets/textfields.dart'; diff --git a/lib/src/presentation/widgets/bottom_sheet.dart b/lib/src/presentation/widgets/bottom_sheet.dart index db9a523..cbd0d70 100644 --- a/lib/src/presentation/widgets/bottom_sheet.dart +++ b/lib/src/presentation/widgets/bottom_sheet.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:gestionuh/src/utils/constants.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +import 'package:get_it/get_it.dart'; class GestionUHBottomSheet extends StatelessWidget { const GestionUHBottomSheet({ @@ -12,21 +14,35 @@ class GestionUHBottomSheet extends StatelessWidget { minimum: const EdgeInsets.only(bottom: 3), child: Center( heightFactor: 2.2, - child: RichText( - text: TextSpan( - style: - Theme.of(context).textTheme.bodyText1!.copyWith(fontSize: 11), - children: [ - const TextSpan(text: '\u00a9 2021'), - TextSpan( - text: Constants.copyRight, + child: FutureBuilder( + future: GetIt.I().getVersion(), + builder: (context, snapshot) { + final textSpans = [ + TextSpan(text: '\u00a9 ${DateTime.now().year}'), + ]; + if (snapshot.hasData) { + textSpans.addAll([ + const TextSpan(text: ' '), + TextSpan( + text: '${Constants.appName} v${snapshot.data}', style: Theme.of(context).textTheme.bodyText1!.copyWith( fontSize: 11, color: Theme.of(context).primaryColor, - )) - ], - ), - textAlign: TextAlign.center, + ), + ), + ]); + } + return RichText( + text: TextSpan( + style: Theme.of(context) + .textTheme + .bodyText1! + .copyWith(fontSize: 11), + children: textSpans, + ), + textAlign: TextAlign.center, + ); + }, ), ), ); diff --git a/lib/src/presentation/widgets/buttons.dart b/lib/src/presentation/widgets/buttons.dart deleted file mode 100644 index d6c7345..0000000 --- a/lib/src/presentation/widgets/buttons.dart +++ /dev/null @@ -1 +0,0 @@ -export 'buttons/default_button.dart'; diff --git a/lib/src/presentation/widgets/buttons/buttons.dart b/lib/src/presentation/widgets/buttons/buttons.dart new file mode 100644 index 0000000..964a057 --- /dev/null +++ b/lib/src/presentation/widgets/buttons/buttons.dart @@ -0,0 +1 @@ +export 'default_button.dart'; diff --git a/lib/src/presentation/widgets/buttons/default_button.dart b/lib/src/presentation/widgets/buttons/default_button.dart index f695580..eb0fec0 100644 --- a/lib/src/presentation/widgets/buttons/default_button.dart +++ b/lib/src/presentation/widgets/buttons/default_button.dart @@ -1,6 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:gestionuh/src/presentation/theme.dart'; +import 'package:gestionuh/src/presentation/theme/theme.dart'; class GestionUhDefaultButton extends StatelessWidget { final Widget? child; @@ -47,7 +47,10 @@ class GestionUhDefaultButton extends StatelessWidget { Text(text!, textScaleFactor: 1.25, style: isSecundary - ? Theme.of(context).textTheme.bodyText2 + ? Theme.of(context) + .primaryTextTheme + .button + ?.copyWith(color: Theme.of(context).primaryColor) : Theme.of(context).primaryTextTheme.button), if (text != null && icon != null) const SizedBox( diff --git a/lib/src/presentation/widgets/drawers.dart b/lib/src/presentation/widgets/drawers.dart deleted file mode 100644 index 48eac4a..0000000 --- a/lib/src/presentation/widgets/drawers.dart +++ /dev/null @@ -1 +0,0 @@ -export 'drawers/default_drawer.dart'; diff --git a/lib/src/presentation/widgets/drawers/default_drawer.dart b/lib/src/presentation/widgets/drawers/default_drawer.dart deleted file mode 100644 index 5592653..0000000 --- a/lib/src/presentation/widgets/drawers/default_drawer.dart +++ /dev/null @@ -1,103 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:gestionuh/deps_injector.dart'; -import 'package:gestionuh/src/data/repository.dart'; -import 'package:gestionuh/src/utils/constants/routes.dart'; - -class DefaultDrawer extends Drawer { - @override - Widget build(BuildContext context) { - final authRepo = di(); - return Drawer( - key: key ?? UniqueKey(), - child: ListView( - children: [ - DrawerHeader( - child: Image.asset( - 'assets/images/logo-uh.png', - color: Theme.of(context).primaryColor, - ), - ), - _buildDrawerItem( - context: context, - text: 'Perfil', - icon: Icons.person, - onTap: () { - Navigator.of(context) - ..pop() - ..pushReplacementNamed(PROFILE_ROUTE_NAME); - }, - ), - _buildDrawerItem( - context: context, - text: 'Mi Cuota', - icon: Icons.data_usage, - onTap: () { - Navigator.of(context) - ..pop() - ..pushReplacementNamed(QUOTA_ROUTE_NAME); - }, - ), - _buildDrawerItem( - context: context, - text: 'Correo', - icon: Icons.mail, - onTap: () { - Navigator.of(context) - ..pop() - ..pushReplacementNamed(MAIL_ROUTE_NAME); - }), - _buildDrawerItem( - context: context, - text: 'Cambiar Contraseña', - icon: Icons.security_rounded, - onTap: () { - Navigator.of(context) - ..pop() - ..pushNamed(RESET_PASSWORD_ROUTE_NAME); - }, - ), - _buildDrawerItem( - context: context, - text: 'Cerrar Sesión', - icon: Icons.logout, - onTap: () async { - await authRepo.logout(); - Navigator.of(context) - ..popUntil( - (route) { - return !(route as MaterialPageRoute).canPop; - }, - ) - ..pushReplacementNamed(LOGIN_ROUTE_NAME); - }, - ), - const Divider(), - _buildDrawerItem( - context: context, - text: 'Acerca de', - icon: Icons.info_outline_rounded, - onTap: () { - Navigator.of(context) - ..pop() - ..pushNamed(ABOUT_ROUTE_NAME); - }, - ), - ], - ), - ); - } - - Widget _buildDrawerItem( - {required BuildContext context, - required String text, - IconData? icon, - Function? onTap}) => - ListTile( - leading: Icon(icon), - title: Text( - text, - style: Theme.of(context).textTheme.subtitle2, - ), - onTap: onTap as void Function()?, - ); -} diff --git a/lib/src/presentation/widgets/flash_helper.dart b/lib/src/presentation/widgets/flash_helper.dart index 62c87c2..9c3c072 100644 --- a/lib/src/presentation/widgets/flash_helper.dart +++ b/lib/src/presentation/widgets/flash_helper.dart @@ -1,9 +1,13 @@ import 'dart:async'; import 'dart:collection'; +import 'dart:ui'; import 'package:flash/flash.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:gestionuh/src/presentation/widgets/buttons/default_button.dart'; +import 'package:gestionuh/src/presentation/widgets/widgets.dart'; +import 'package:gestionuh/src/utils/constants/messages.dart'; class _MessageItem { final String message; @@ -335,7 +339,7 @@ class FlashHelper { borderRadius: const BorderRadius.all(Radius.circular(8.0)), child: const Padding( padding: EdgeInsets.all(16.0), - child: CircularProgressIndicator(strokeWidth: 2.0), + child: GestionUhLoadingIndicator(strokeWidth: 2.0), ), ), ); @@ -398,6 +402,143 @@ class FlashHelper { }, ); } + + static Future aceptDeclineDialog(BuildContext context) { + bool acceptAvailable = false; + bool disposedScrollController = false; + final scrollController = ScrollController(); + return showFlash( + context: context, + persistent: false, + onWillPop: () async => false, + builder: (context, controller) { + final theme = Theme.of(context); + + return StatefulBuilder( + builder: (context, setState) { + if (!disposedScrollController) { + scrollController.addListener(() { + final maxScroll = scrollController.position.maxScrollExtent; + final currentScroll = scrollController.position.pixels; + if (!acceptAvailable && maxScroll == currentScroll) { + setState(() { + acceptAvailable = true; + }); + } + }); + WidgetsBinding.instance!.addPostFrameCallback((_) { + // in case that there is no need to scroll + if (!acceptAvailable && + scrollController.position.pixels == + scrollController.position.maxScrollExtent) { + setState(() { + acceptAvailable = true; + }); + } + }); + } + + return SafeArea( + child: Flash.dialog( + controller: controller, + borderWidth: 3, + borderRadius: const BorderRadius.all(Radius.circular(8.0)), + child: FlashBar( + title: Text(TERMS_AND_CONDITIONS_OF_USE_TITLE, + style: theme.textTheme.headline6?.copyWith( + fontSize: 20.0, color: theme.primaryColor)), + message: Container( + height: MediaQuery.of(context).size.height * 0.58, + padding: const EdgeInsets.all(3), + decoration: BoxDecoration( + borderRadius: + const BorderRadius.all(Radius.circular(8)), + boxShadow: [ + BoxShadow( + color: theme.primaryColor.withOpacity(0.05), + blurRadius: 1) + ]), + child: Stack( + children: [ + SingleChildScrollView( + controller: disposedScrollController + ? ScrollController() + : scrollController, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(TERMS_AND_CONDITIONS_OF_USE_SUBTITLE, + style: theme.textTheme.bodyText1 + ?.copyWith(color: theme.primaryColor)), + Text(TERMS_AND_CONDITIONS_OF_USE_ENUM_TERMS, + style: theme.textTheme.bodyText2), + ], + ), + ), + if (!acceptAvailable) + Positioned( + bottom: 10, + right: 1, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Colors.white, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(100))), + ), + onPressed: () { + scrollController.animateTo( + scrollController.position.maxScrollExtent, + curve: Curves.easeOut, + duration: const Duration(milliseconds: 300), + ); + }, + child: const Icon( + Icons.keyboard_arrow_down, + color: Colors.black45, + size: 30, + ), + )), + ], + ), + ), + leftBarIndicatorColor: theme.primaryColor, + actions: [ + GestionUhDefaultButton( + isSecundary: true, + onPressed: () { + if (!disposedScrollController) { + setState(() { + disposedScrollController = true; + scrollController.dispose(); + controller.dismiss(false); + }); + } + }, + text: 'No Acepto', + // child: const Text('No acepto'), + ), + GestionUhDefaultButton( + onPressed: acceptAvailable + ? () => disposedScrollController + ? null + : setState(() { + disposedScrollController = true; + scrollController.dispose(); + controller.dismiss(true); + }) + : null, + text: 'Acepto', + ), + ], + ), + ), + ); + }, + ); + }, + ); + } } typedef ChildBuilder = Widget Function( diff --git a/lib/src/presentation/widgets/loading_indicators.dart b/lib/src/presentation/widgets/loading_indicators.dart deleted file mode 100644 index c47bcf1..0000000 --- a/lib/src/presentation/widgets/loading_indicators.dart +++ /dev/null @@ -1 +0,0 @@ -export 'loading_indicators/circular_loading.dart'; diff --git a/lib/src/presentation/widgets/loading_indicators/circular_loading.dart b/lib/src/presentation/widgets/loading_indicators/circular_loading.dart index c4b8ca8..66a3632 100644 --- a/lib/src/presentation/widgets/loading_indicators/circular_loading.dart +++ b/lib/src/presentation/widgets/loading_indicators/circular_loading.dart @@ -1,11 +1,19 @@ import 'package:flutter/material.dart'; class GestionUhLoadingIndicator extends StatelessWidget { - const GestionUhLoadingIndicator({Key? key, this.color}) : super(key: key); final Color? color; + final double strokeWidth; + + const GestionUhLoadingIndicator({ + Key? key, + this.color, + this.strokeWidth = 4.0, + }) : super(key: key); + @override Widget build(BuildContext context) { return CircularProgressIndicator( + strokeWidth: strokeWidth, valueColor: AlwaysStoppedAnimation(color ?? Theme.of(context).primaryColor), ); diff --git a/lib/src/presentation/widgets/loading_indicators/loading_indicators.dart b/lib/src/presentation/widgets/loading_indicators/loading_indicators.dart new file mode 100644 index 0000000..59ebe56 --- /dev/null +++ b/lib/src/presentation/widgets/loading_indicators/loading_indicators.dart @@ -0,0 +1 @@ +export 'circular_loading.dart'; diff --git a/lib/src/presentation/widgets/mail_quota_graph.dart b/lib/src/presentation/widgets/mail_quota_graph.dart index f0873e1..b36dfeb 100644 --- a/lib/src/presentation/widgets/mail_quota_graph.dart +++ b/lib/src/presentation/widgets/mail_quota_graph.dart @@ -1,8 +1,8 @@ import 'dart:math'; -import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; class MailQuotaGraph extends StatelessWidget { final MailQuota quota; @@ -40,45 +40,73 @@ class MailQuotaGraph extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - Text( - 'Consumo (en MB)', - style: Theme.of(context).textTheme.subtitle2, - ), + // Text( + // 'Consumo (en MB)', + // style: Theme.of(context).textTheme.subtitle2, + // ), + // Container( + // margin: const EdgeInsets.all(20), + // height: 250, + // child: PieChart( + // PieChartData( + // borderData: FlBorderData(show: false), + // sections: data + // .where((x) => x.cant != 0) + // .map((item) => PieChartSectionData( + // radius: 50, + // color: item.color, + // value: item.cant.toDouble(), + // showTitle: false, + // )) + // .toList(), + // ), + // ), + // ), + // for (var item in data) + // ListTile( + // leading: Icon( + // Icons.circle, + // color: item.color, + // ), + // title: Text( + // item.title, + // style: Theme.of(context).textTheme.subtitle2, + // ), + // trailing: Text( + // '${item.cant} MB', + // style: Theme.of(context).textTheme.subtitle2, + // ), + // ), Container( - margin: const EdgeInsets.all(20), - height: 250, - child: PieChart( - PieChartData( - borderData: FlBorderData(show: false), - sectionsSpace: 0, - centerSpaceRadius: MediaQuery.of(context).size.width / 6, - sections: data - .where((x) => x.cant != 0) - .map((item) => PieChartSectionData( - radius: 50, - color: item.color, - value: item.cant.toDouble(), - showTitle: false, - )) - .toList(), - ), - ), - ), - for (var item in data) - ListTile( - leading: Icon( - Icons.circle, - color: item.color, - ), - title: Text( - item.title, - style: Theme.of(context).textTheme.subtitle2, + margin: const EdgeInsets.symmetric(horizontal: 20), + height: MediaQuery.of(context).size.height * 0.65, + child: SfCircularChart( + title: ChartTitle( + text: 'Consumo (en MB)', + textStyle: Theme.of(context).textTheme.subtitle2, ), - trailing: Text( - '${item.cant} MB', - style: Theme.of(context).textTheme.subtitle2, + legend: Legend( + isVisible: true, + overflowMode: LegendItemOverflowMode.wrap, + position: LegendPosition.bottom, + textStyle: Theme.of(context).textTheme.subtitle2, ), + tooltipBehavior: TooltipBehavior(enable: true), + series: [ + DoughnutSeries( + dataSource: data, + xValueMapper: (data, _) => data.title, + yValueMapper: (data, _) => data.cant, + pointColorMapper: (data, _) => data.color, + dataLabelSettings: DataLabelSettings( + isVisible: true, + labelPosition: ChartDataLabelPosition.outside, + useSeriesColor: true, + ), + ), + ], ), + ), ], ); } diff --git a/lib/src/presentation/widgets/quota_graph.dart b/lib/src/presentation/widgets/quota_graph.dart index c36d46e..81281a4 100644 --- a/lib/src/presentation/widgets/quota_graph.dart +++ b/lib/src/presentation/widgets/quota_graph.dart @@ -1,8 +1,8 @@ import 'dart:math'; -import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; -import 'package:gestionuh/src/data/models.dart'; +import 'package:gestionuh/src/data/models/models.dart'; +import 'package:syncfusion_flutter_charts/charts.dart'; class QuotaGraph extends StatelessWidget { final Quota quota; @@ -50,45 +50,36 @@ class QuotaGraph extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - Text( - 'Consumo (en MB)', - style: Theme.of(context).textTheme.subtitle2, - ), Container( - margin: const EdgeInsets.all(20), - height: 250, - child: PieChart( - PieChartData( - borderData: FlBorderData(show: false), - sectionsSpace: 0, - centerSpaceRadius: MediaQuery.of(context).size.width / 6, - sections: data - .where((x) => x.cant != 0) - .map((item) => PieChartSectionData( - radius: 50, - color: item.color, - value: item.cant.toDouble(), - showTitle: false, - )) - .toList(), - ), - ), - ), - for (var item in data) - ListTile( - leading: Icon( - Icons.circle, - color: item.color, - ), - title: Text( - item.title, - style: Theme.of(context).textTheme.subtitle2, + margin: const EdgeInsets.symmetric(horizontal: 20), + height: MediaQuery.of(context).size.height * 0.65, + child: SfCircularChart( + title: ChartTitle( + text: 'Consumo (en MB)', + textStyle: Theme.of(context).textTheme.subtitle2, ), - trailing: Text( - '${item.cant} MB', - style: Theme.of(context).textTheme.subtitle2, + legend: Legend( + isVisible: true, + overflowMode: LegendItemOverflowMode.wrap, + position: LegendPosition.bottom, + textStyle: Theme.of(context).textTheme.subtitle2, ), + tooltipBehavior: TooltipBehavior(enable: true), + series: [ + DoughnutSeries( + dataSource: data, + xValueMapper: (data, _) => data.title, + yValueMapper: (data, _) => data.cant, + pointColorMapper: (data, _) => data.color, + dataLabelSettings: DataLabelSettings( + isVisible: true, + labelPosition: ChartDataLabelPosition.outside, + useSeriesColor: true, + ), + ), + ], ), + ), ], ); } diff --git a/lib/src/presentation/widgets/textfields.dart b/lib/src/presentation/widgets/textfields.dart deleted file mode 100644 index 210aa63..0000000 --- a/lib/src/presentation/widgets/textfields.dart +++ /dev/null @@ -1 +0,0 @@ -export 'textfields/default_textfield.dart'; diff --git a/lib/src/presentation/widgets/textfields/default_textfield.dart b/lib/src/presentation/widgets/textfields/default_textfield.dart index aa2c4f9..751ee87 100644 --- a/lib/src/presentation/widgets/textfields/default_textfield.dart +++ b/lib/src/presentation/widgets/textfields/default_textfield.dart @@ -57,95 +57,75 @@ class GestionUhDefaultTextFieldState extends State { @override Widget build(BuildContext context) { - return Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: TextFormField( - validator: widget.validator, - inputFormatters: widget.inputFormatters ?? [], - autovalidateMode: - widget.autovalidateMode ?? AutovalidateMode.onUserInteraction, - style: widget.style ?? const TextStyle(fontSize: 17), - onChanged: widget.onChanged, - onTap: widget.onTap as void Function()?, - controller: widget.controller, - keyboardType: widget.keyboardType, - textAlignVertical: TextAlignVertical.center, - textInputAction: TextInputAction.done, - textAlign: TextAlign.justify, - cursorColor: Theme.of(context).accentColor, - obscureText: _obscureText, - decoration: InputDecoration( - fillColor: Theme.of(context).cardColor, - filled: true, - contentPadding: const EdgeInsets.only(left: 10), - labelStyle: widget.labelStyle ?? - Theme.of(context) - .textTheme - .bodyText1! - .copyWith(color: Theme.of(context).primaryColor), - hintStyle: - widget.hintStyle ?? Theme.of(context).textTheme.bodyText1, - enabledBorder: OutlineInputBorder( - borderRadius: widget.borderRadius ?? - const BorderRadius.all(Radius.circular(5)), - borderSide: BorderSide( - color: Colors.grey[300]!, - ), - ), - border: OutlineInputBorder( - borderRadius: widget.borderRadius ?? - const BorderRadius.all( - Radius.circular(5), - ), - borderSide: BorderSide( - color: Colors.grey[300]!, - ), + return TextFormField( + validator: widget.validator, + inputFormatters: widget.inputFormatters ?? [], + autovalidateMode: + widget.autovalidateMode ?? AutovalidateMode.onUserInteraction, + style: widget.style ?? const TextStyle(fontSize: 17), + onChanged: widget.onChanged, + onTap: widget.onTap as void Function()?, + controller: widget.controller, + keyboardType: widget.keyboardType, + textAlignVertical: TextAlignVertical.center, + textInputAction: TextInputAction.done, + textAlign: TextAlign.justify, + cursorColor: Theme.of(context).accentColor, + obscureText: _obscureText, + decoration: InputDecoration( + fillColor: Theme.of(context).cardColor, + filled: true, + contentPadding: const EdgeInsets.only(left: 10), + labelStyle: widget.labelStyle ?? + Theme.of(context) + .textTheme + .bodyText1! + .copyWith(color: Theme.of(context).primaryColor), + hintStyle: widget.hintStyle ?? Theme.of(context).textTheme.bodyText1, + enabledBorder: OutlineInputBorder( + borderRadius: + widget.borderRadius ?? const BorderRadius.all(Radius.circular(5)), + borderSide: BorderSide( + color: Colors.grey[300]!, + ), + ), + border: OutlineInputBorder( + borderRadius: widget.borderRadius ?? + const BorderRadius.all( + Radius.circular(5), ), - focusedBorder: OutlineInputBorder( - borderRadius: widget.borderRadius ?? - const BorderRadius.all( - Radius.circular(5), - ), + borderSide: BorderSide( + color: Colors.grey[300]!, + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: widget.borderRadius ?? + const BorderRadius.all( + Radius.circular(5), ), - errorBorder: OutlineInputBorder( - borderRadius: widget.borderRadius ?? - const BorderRadius.all( - Radius.circular(5), - ), - borderSide: BorderSide( - color: Colors.red.withOpacity(.5), - ), + ), + errorBorder: OutlineInputBorder( + borderRadius: widget.borderRadius ?? + const BorderRadius.all( + Radius.circular(5), ), - labelText: widget.labelText, - hintText: widget.hintText, - ), + borderSide: BorderSide( + color: Colors.red.withOpacity(.5), ), ), - if (widget.keyboardType == TextInputType.visiblePassword) - SizedBox( - width: 40, - child: Material( - color: Theme.of(context).primaryColor, - clipBehavior: Clip.antiAlias, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topRight: Radius.circular(5), - bottomRight: Radius.circular(20), - ), - ), - child: IconButton( + labelText: widget.labelText, + hintText: widget.hintText, + suffixIcon: widget.keyboardType == TextInputType.visiblePassword + ? IconButton( color: Colors.red, icon: Icon( _obscureText ? Icons.visibility : Icons.visibility_off, - color: Theme.of(context).cardColor, + color: Theme.of(context).primaryColor, ), onPressed: _toggleVisible, - ), - ), - ), - ], + ) + : null, + ), ); } } diff --git a/lib/src/presentation/widgets/textfields/textfields.dart b/lib/src/presentation/widgets/textfields/textfields.dart new file mode 100644 index 0000000..03c3dd3 --- /dev/null +++ b/lib/src/presentation/widgets/textfields/textfields.dart @@ -0,0 +1 @@ +export 'default_textfield.dart'; diff --git a/lib/src/presentation/widgets/widgets.dart b/lib/src/presentation/widgets/widgets.dart new file mode 100644 index 0000000..9ccf6df --- /dev/null +++ b/lib/src/presentation/widgets/widgets.dart @@ -0,0 +1,7 @@ +export 'bottom_sheet.dart'; +export 'buttons/buttons.dart'; +export 'flash_helper.dart'; +export 'loading_indicators/loading_indicators.dart'; +export 'mail_quota_graph.dart'; +export 'quota_graph.dart'; +export 'textfields/textfields.dart'; diff --git a/lib/src/router.dart b/lib/src/router.dart new file mode 100644 index 0000000..18f975a --- /dev/null +++ b/lib/src/router.dart @@ -0,0 +1,86 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gestionuh/src/data/repositories/repositories.dart'; +import 'package:gestionuh/src/presentation/blocs/blocs.dart'; +import 'package:gestionuh/src/presentation/pages/pages.dart'; +import 'package:gestionuh/src/utils/constants/constants.dart'; +import 'package:get_it/get_it.dart'; +import 'package:page_transition/page_transition.dart'; + +class RouterNavigation { + static Route? onGenerateRoute(RouteSettings settings) { + switch (settings.name) { + case LOGIN_ROUTE_NAME: + final authRepo = GetIt.I(); + if (authRepo.logged) { + return _buildPage( + builder: BlocProvider( + create: (_) => GetIt.I()..add(const HomeEvent.loadProfile()), + child: HomePage(), + ), + settings: settings, + ); + } + return _buildPage( + builder: BlocProvider( + create: (_) => GetIt.I(), + child: const LoginPage(), + ), + settings: settings, + ); + case REGISTER_ROUTE_NAME: + return _buildPage( + builder: Overlay( + initialEntries: [ + OverlayEntry(builder: (context) { + return BlocProvider( + create: (_) => + GetIt.I()..add(const RegisterEvent.questionsRequested()), + child: const RegisterPage(), + ); + }), + ], + ), + settings: settings, + ); + case RECOVER_PASSWORD_ROUTE_NAME: + return _buildPage( + builder: BlocProvider( + create: (_) => GetIt.I(), + child: RecoverPasswordPage(), + ), + settings: settings, + ); + case HOME_ROUTE_NAME: + default: + final authRepo = GetIt.I(); + if (authRepo.logged) { + return _buildPage( + builder: BlocProvider( + create: (_) => GetIt.I()..add(const HomeEvent.loadProfile()), + child: HomePage(), + ), + settings: settings, + ); + } + return _buildPage( + builder: BlocProvider( + create: (_) => GetIt.I(), + child: const LoginPage(), + ), + settings: settings, + ); + } + } + + static PageRoute _buildPage({ + required Widget builder, + required RouteSettings settings, + }) { + return PageTransition( + child: builder, + settings: settings, + type: PageTransitionType.fade, + ); + } +} diff --git a/lib/src/utils/configurations/configure_nonweb.dart b/lib/src/utils/configurations/configure_nonweb.dart new file mode 100644 index 0000000..f58bb02 --- /dev/null +++ b/lib/src/utils/configurations/configure_nonweb.dart @@ -0,0 +1,3 @@ +void configureApp() { + // No-op. +} diff --git a/lib/src/utils/configurations/configure_web.dart b/lib/src/utils/configurations/configure_web.dart new file mode 100644 index 0000000..ccc1829 --- /dev/null +++ b/lib/src/utils/configurations/configure_web.dart @@ -0,0 +1,5 @@ +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; + +void configureApp() { + setUrlStrategy(PathUrlStrategy()); +} diff --git a/lib/src/utils/constants.dart b/lib/src/utils/constants.dart deleted file mode 100644 index eaec5ff..0000000 --- a/lib/src/utils/constants.dart +++ /dev/null @@ -1,7 +0,0 @@ -export 'constants/about.dart'; -export 'constants/constants.dart'; -export 'constants/errors.dart'; -export 'constants/misc.dart'; -export 'constants/routes.dart'; -export 'constants/sample_data.dart'; -export 'constants/storage_keys.dart'; diff --git a/lib/src/utils/constants/constants.dart b/lib/src/utils/constants/constants.dart index 2316396..d9455fe 100644 --- a/lib/src/utils/constants/constants.dart +++ b/lib/src/utils/constants/constants.dart @@ -1 +1,9 @@ +export 'about.dart'; +export 'errors.dart'; +export 'messages.dart'; +export 'misc.dart'; +export 'routes.dart'; +export 'sample_data.dart'; +export 'storage_keys.dart'; + const NUMBER_OF_SECURITY_QUESTIONS_NEEDED = 3; diff --git a/lib/src/utils/constants/errors.dart b/lib/src/utils/constants/errors.dart index 0049080..5185905 100644 --- a/lib/src/utils/constants/errors.dart +++ b/lib/src/utils/constants/errors.dart @@ -1,14 +1,18 @@ class Errors { - static const Messages = {1: 'Datos inválidos.', 2: 'Credenciales inválidas.'}; + static const Messages = { + 1: 'Datos inválidos.', + 2: 'Credenciales inválidas.', + 20: 'Datos inválidos.', + }; static const DefaultError = 'Ha ocurrido un error.'; - static String? retrieveError(String message) { - try { - final index = int.parse(message); - return Messages[index]; - } catch (_) {} + static const ConnectionError = 'Conexión fallida. Verifique su conectividad.'; - return DefaultError; + static String? retrieveError(String message) { + final index = int.tryParse(message); + return index != null && Messages.containsKey(index) + ? Messages[index] + : DefaultError; } } diff --git a/lib/src/utils/constants/messages.dart b/lib/src/utils/constants/messages.dart new file mode 100644 index 0000000..7908e69 --- /dev/null +++ b/lib/src/utils/constants/messages.dart @@ -0,0 +1,31 @@ +// TERMS AND CONDITIONS TEXTS +const TERMS_AND_CONDITIONS_OF_USE_TITLE = + 'ÉTICA PARA EL EMPLEO DE LAS TECNOLOGÍAS EN LA UNIVERSIDAD DE LA HABANA'; + +const TERMS_AND_CONDITIONS_OF_USE_SUBTITLE = + ' Las redes y servicios de la Universidad de la Habana tienen como objetivo facilitar el intercambio de información, aprendizaje y trabajo colaborativo de sus usuarios, los que se comprometen a cumplir los siguientes principios en el uso de las tecnologías: '; + +const TERMS_AND_CONDITIONS_OF_USE_ENUM_TERMS = + '\n1.Cumplir con las disposiciones de seguridad informática vigentes a nivel nacional. ' + '\n' + '\n2.No realizar hechos delictivos ni lesivos a la dignidad humana. ' + '\n' + '\n3.No perjudicar a personas o instituciones. ' + '\n' + '\n4.No acceder sin autorización a información ajena. ' + '\n' + '\n5.No acceder o difundir información falsa, ni contraria a los principios éticos y morales de la sociedad. ' + '\n' + '\n6.No enviar spam. ' + '\n' + '\n7.No apropiarse de la producción intelectual de otras personas. ' + '\n' + '\n8.Ser responsable en el uso, diseño y desarrollo de aplicaciones informáticas. ' + '\n' + '\n9.Proteger los medios e información digital bajo su responsabilidad. ' + '\n' + '\n10.Alertar a la administración sobre comportamientos anormales en la red o los servicios, que puedan ser producto de ataques informáticos u otras causas. ' + '\n' + '\nLas cuentas asignadas a los usuarios serán auditadas con vistas a verificar el cumplimiento de la ética. ' + '\n' + '\nAcepto cumplir con todo lo antes expuesto.'; diff --git a/lib/src/utils/constants/misc.dart b/lib/src/utils/constants/misc.dart index ee9e72f..db525d4 100644 --- a/lib/src/utils/constants/misc.dart +++ b/lib/src/utils/constants/misc.dart @@ -1,5 +1,5 @@ class Constants { - static const appName = 'Gestion UH'; + static const appName = 'Gestión UH'; static const testMode = false; static const authUrl = '/auth/login'; static const quotaUrl = '/proxy/quota'; @@ -11,7 +11,6 @@ class Constants { static const passwordRecoveryUrl = '/auth/resetpassword'; static const userSecurityQuestionsUrl = '/user/securityquestions'; static const baseUrl = 'https://identity.sic.uh.cu'; - static const copyRight = ' GestiónUH version 0.1.0 Beta'; static const objectClassTranslations = { 'student': 'Estudiante', 'worker': 'Trabajador' diff --git a/lib/src/utils/constants/routes.dart b/lib/src/utils/constants/routes.dart index 84f8c85..e5f5bae 100644 --- a/lib/src/utils/constants/routes.dart +++ b/lib/src/utils/constants/routes.dart @@ -1,8 +1,9 @@ const LOGIN_ROUTE_NAME = '/login'; const REGISTER_ROUTE_NAME = '/register'; -const QUOTA_ROUTE_NAME = '/quota'; -const PROFILE_ROUTE_NAME = '/profile'; -const MAIL_ROUTE_NAME = '/mail'; -const RESET_PASSWORD_ROUTE_NAME = '/reset_password'; -const ABOUT_ROUTE_NAME = '/about'; -const RECOVER_PASSWORD_ROUTE_NAME = '/recover_password'; +const HOME_ROUTE_NAME = '/'; +const RECOVER_PASSWORD_ROUTE_NAME = '/recover-password'; +// const QUOTA_ROUTE_NAME = '/quota'; +// const PROFILE_ROUTE_NAME = '/profile'; +// const MAIL_ROUTE_NAME = '/mail'; +// const RESET_PASSWORD_ROUTE_NAME = '/reset-password'; +// const ABOUT_ROUTE_NAME = '/about'; diff --git a/lib/src/utils/constants/storage_keys.dart b/lib/src/utils/constants/storage_keys.dart index 12cf946..a5db0c2 100644 --- a/lib/src/utils/constants/storage_keys.dart +++ b/lib/src/utils/constants/storage_keys.dart @@ -1,4 +1,4 @@ -const STORAGE_PREFIX = 'gestion_uh-'; +const STORAGE_PREFIX = 'gestionuh.'; const USER_NAME = '${STORAGE_PREFIX}username'; const USER_PASSWORD = '${STORAGE_PREFIX}password'; diff --git a/lib/src/utils/simple_bloc_observer.dart b/lib/src/utils/simple_bloc_observer.dart new file mode 100644 index 0000000..c10324e --- /dev/null +++ b/lib/src/utils/simple_bloc_observer.dart @@ -0,0 +1,11 @@ +import 'dart:developer'; + +import 'package:flutter_bloc/flutter_bloc.dart'; + +class SimpleBlocObserver extends BlocObserver { + @override + void onTransition(Bloc bloc, Transition transition) { + super.onTransition(bloc, transition); + log(transition.toString()); + } +} diff --git a/lib/src/utils/validators.dart b/lib/src/utils/validators.dart index 00d6e40..32bda49 100644 --- a/lib/src/utils/validators.dart +++ b/lib/src/utils/validators.dart @@ -1,6 +1,8 @@ String? safetyPasswordValidator(String? value) { if (value == null || value.length < 8) { return 'Debe contener al menos 8 caracteres'; + } else if (value.length != value.trim().length) { + return 'No se permiten espacios al inicio o al final'; } else if (!value.contains(RegExp(r'[!#$@\[\]\\.,%&*+/=?^_`{|}~-]'))) { return 'Debe contener al menos un caracter especial'; } else if (!value.contains(RegExp('[0-9]'))) { @@ -16,7 +18,9 @@ String? safetyPasswordValidator(String? value) { } String? identityNumberCIValidator(String? value) { - if (value == null || int.tryParse(value) == null) { + if (value == null || value == '') { + return 'No puede estar vacío'; + } else if (int.tryParse(value) == null) { return 'Sólo se admiten dígitos'; } else if (value.length < 11) { return 'Faltan dígitos de su número de Carnet de Identidad'; @@ -28,7 +32,27 @@ String? identityNumberCIValidator(String? value) { String? answerValidator(String? value) { if (value == null || value.isEmpty) { - return 'Debe responder la pregunta seleccionada.'; + return 'Debe responder la pregunta seleccionada'; + } + if (value.length != value.trim().length) { + return 'No puede contener espacios al inicio o al final'; + } + return null; +} + +String? userNameValidator(String? value) { + if (value == null || value.isEmpty) { + return 'Debe introducir su nombre de usuario'; + } + if (value.length != value.trim().length) { + return 'No puede contener espacios al inicio o al final'; + } + return null; +} + +String? currentPasswordValidator(String? value) { + if (value == null || value.isEmpty) { + return 'Debe escribir su antigua contraseña'; } return null; } diff --git a/pubspec.lock b/pubspec.lock index df661ad..6d232db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "20.0.0" + version: "21.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.5.0" archive: dependency: transitive description: @@ -56,56 +56,56 @@ packages: name: build url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" build_config: dependency: transitive description: name: build_config url: "https://pub.dartlang.org" source: hosted - version: "0.4.7" + version: "1.0.0" build_daemon: dependency: transitive description: name: build_daemon url: "https://pub.dartlang.org" source: hosted - version: "2.1.7" + version: "3.0.0" build_resolvers: dependency: transitive description: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" build_runner: dependency: "direct dev" description: name: build_runner url: "https://pub.dartlang.org" source: hosted - version: "1.12.2" + version: "2.0.1" build_runner_core: dependency: transitive description: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "6.1.12" + version: "7.0.0" built_collection: dependency: transitive description: name: built_collection url: "https://pub.dartlang.org" source: hosted - version: "4.3.2" + version: "5.0.0" built_value: dependency: transitive description: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "7.1.0" + version: "8.0.5" characters: dependency: transitive description: @@ -147,7 +147,7 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "3.6.0" + version: "4.0.0" collection: dependency: "direct main" description: @@ -190,13 +190,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" - equatable: - dependency: transitive - description: - name: equatable - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" fake_async: dependency: transitive description: @@ -224,14 +217,7 @@ packages: name: fixnum url: "https://pub.dartlang.org" source: hosted - version: "0.10.11" - fl_chart: - dependency: "direct main" - description: - name: fl_chart - url: "https://pub.dartlang.org" - source: hosted - version: "0.35.0" + version: "1.0.0" flash: dependency: "direct main" description: @@ -264,7 +250,7 @@ packages: name: flutter_native_splash url: "https://pub.dartlang.org" source: hosted - version: "1.1.7+1" + version: "1.1.8+4" flutter_secure_storage: dependency: "direct main" description: @@ -278,17 +264,31 @@ packages: source: sdk version: "0.0.0" flutter_web_plugins: - dependency: transitive + dependency: "direct main" description: flutter source: sdk version: "0.0.0" + freezed: + dependency: "direct dev" + description: + name: freezed + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.1+3" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.1" get_it: dependency: "direct main" description: name: get_it url: "https://pub.dartlang.org" source: hosted - version: "6.0.0" + version: "6.1.1" glob: dependency: transitive description: @@ -302,14 +302,21 @@ packages: name: graphs url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "2.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.1" http_multi_server: dependency: transitive description: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.0.1" http_parser: dependency: transitive description: @@ -324,13 +331,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.2" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.4" + version: "1.0.0" js: dependency: transitive description: @@ -351,7 +365,7 @@ packages: name: json_serializable url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.1.1" lint: dependency: "direct dev" description: @@ -386,7 +400,7 @@ packages: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.7" + version: "1.0.0" nested: dependency: transitive description: @@ -401,6 +415,55 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + package_info_plus_web: + dependency: transitive + description: + name: package_info_plus_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + page_transition: + dependency: "direct main" + description: + name: page_transition + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1-nullsafety.0" path: dependency: transitive description: @@ -428,7 +491,7 @@ packages: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.1" pedantic: dependency: transitive description: @@ -492,13 +555,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" - quiver: - dependency: transitive + responsive_builder: + dependency: "direct main" description: - name: quiver + name: responsive_builder url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "0.4.1" shared_preferences: dependency: "direct main" description: @@ -547,14 +610,14 @@ packages: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.4+1" + version: "1.0.1" sky_engine: dependency: transitive description: flutter @@ -602,6 +665,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + syncfusion_flutter_charts: + dependency: "direct main" + description: + name: syncfusion_flutter_charts + url: "https://pub.dartlang.org" + source: hosted + version: "19.1.57+1" + syncfusion_flutter_core: + dependency: transitive + description: + name: syncfusion_flutter_core + url: "https://pub.dartlang.org" + source: hosted + version: "19.1.57+1" term_glyph: dependency: transitive description: @@ -622,7 +699,7 @@ packages: name: timing url: "https://pub.dartlang.org" source: hosted - version: "0.1.1+3" + version: "1.0.0" typed_data: dependency: transitive description: @@ -630,6 +707,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + universal_io: + dependency: transitive + description: + name: universal_io + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.4" url_launcher: dependency: "direct main" description: @@ -692,7 +776,7 @@ packages: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "2.0.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 17a2a7d..b71de02 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: gestionuh -description: A UH managment app +description: Aplicación para la gestión electrónica en la Universidad de La Habana. publish_to: 'none' @@ -12,24 +12,31 @@ dependencies: collection: ^1.15.0-nullsafety.4 cupertino_icons: ^1.0.2 dio: ^4.0.0 - fl_chart: ^0.35.0 flash: ^1.5.1 flutter: sdk: flutter flutter_bloc: ^7.0.0 flutter_secure_storage: ^4.1.0 - get_it: ^6.0.0 + flutter_web_plugins: + sdk: flutter + freezed_annotation: ^0.14.1 + get_it: ^6.1.1 json_annotation: ^4.0.1 + package_info_plus: ^1.0.0 + page_transition: ^2.0.1-nullsafety.0 + responsive_builder: ^0.4.1 shared_preferences: ^2.0.5 + syncfusion_flutter_charts: ^19.1.57+1 url_launcher: ^6.0.3 dev_dependencies: - build_runner: ^1.12.2 + build_runner: ^2.0.1 flutter_launcher_icons: ^0.9.0 - flutter_native_splash: ^1.1.7+1 + flutter_native_splash: ^1.1.8+4 flutter_test: sdk: flutter - json_serializable: ^4.1.0 + freezed: ^0.14.1+3 + json_serializable: ^4.1.1 lint: ^1.5.3 flutter: @@ -45,4 +52,4 @@ flutter_native_splash: flutter_icons: android: 'launcher_icon' ios: true - image_path: 'assets/images/ico.png' + image_path: 'assets/images/icon.png' diff --git a/web/favicon.png b/web/favicon.png new file mode 100644 index 0000000..f6bd121 Binary files /dev/null and b/web/favicon.png differ diff --git a/web/icons/Icon-192.png b/web/icons/Icon-192.png new file mode 100644 index 0000000..10b34bc Binary files /dev/null and b/web/icons/Icon-192.png differ diff --git a/web/icons/Icon-512.png b/web/icons/Icon-512.png new file mode 100644 index 0000000..7c9839b Binary files /dev/null and b/web/icons/Icon-512.png differ diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..9ea947a --- /dev/null +++ b/web/index.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + Gestión UH + + + + + + + + diff --git a/web/manifest.json b/web/manifest.json new file mode 100644 index 0000000..28304ad --- /dev/null +++ b/web/manifest.json @@ -0,0 +1,23 @@ +{ + "name": "Gestión UH", + "short_name": "Gestión UH", + "start_url": ".", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#ffffff", + "description": "Aplicación para la gestión electrónica en la Universidad de La Habana.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} \ No newline at end of file