From 833c4c85b6c150174e7ac70b4d63d65c2c8031d4 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Fri, 24 Feb 2023 10:12:04 +0100 Subject: [PATCH] chore: fix all problems --- .../state_management/albums_screen.dart | 2 +- .../photo_details_screen.dart | 2 +- .../state_management/photos_screen.dart | 2 +- .../blocs/edit_profile_cubit.dart | 74 +++++++++++++++++++ .../wyatt_bloc_helper/example/lib/main.dart | 4 +- .../example/lib/bloc/example_cubit.dart | 16 ++-- .../wyatt_form_bloc/example/lib/main.dart | 8 +- .../example/http_client_example.dart | 2 +- .../example/http_client_fastapi_example.dart | 34 ++++----- .../wyatt_http_client/example/pipeline.dart | 6 +- .../wyatt_http_client/lib/src/pipeline.dart | 2 + 11 files changed, 113 insertions(+), 39 deletions(-) create mode 100644 packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart diff --git a/packages/wyatt_architecture/example/lib/presentation/features/albums/state_management/albums_screen.dart b/packages/wyatt_architecture/example/lib/presentation/features/albums/state_management/albums_screen.dart index 2aae70fd..b180827e 100644 --- a/packages/wyatt_architecture/example/lib/presentation/features/albums/state_management/albums_screen.dart +++ b/packages/wyatt_architecture/example/lib/presentation/features/albums/state_management/albums_screen.dart @@ -35,7 +35,7 @@ class AlbumsScreen extends BlocScreen { bloc..add(AlbumFetched()); @override - Widget onWrap(BuildContext context, Widget child) => AlbumsWrapperWidget( + Widget parent(BuildContext context, Widget child) => AlbumsWrapperWidget( child: child, ); diff --git a/packages/wyatt_architecture/example/lib/presentation/features/photo_details/state_management/photo_details_screen.dart b/packages/wyatt_architecture/example/lib/presentation/features/photo_details/state_management/photo_details_screen.dart index 4cbc2e83..98a41c54 100644 --- a/packages/wyatt_architecture/example/lib/presentation/features/photo_details/state_management/photo_details_screen.dart +++ b/packages/wyatt_architecture/example/lib/presentation/features/photo_details/state_management/photo_details_screen.dart @@ -43,7 +43,7 @@ class PhotoDetailsScreen bloc..load(photoId); @override - Widget onWrap(BuildContext context, Widget child) => + Widget parent(BuildContext context, Widget child) => PhotoDetailsWrapperWidget(child: child); @override diff --git a/packages/wyatt_architecture/example/lib/presentation/features/photos/state_management/photos_screen.dart b/packages/wyatt_architecture/example/lib/presentation/features/photos/state_management/photos_screen.dart index 57ceef4e..bf9352dd 100644 --- a/packages/wyatt_architecture/example/lib/presentation/features/photos/state_management/photos_screen.dart +++ b/packages/wyatt_architecture/example/lib/presentation/features/photos/state_management/photos_screen.dart @@ -37,7 +37,7 @@ class PhotosScreen extends BlocScreen { bloc..add(PhotoFetched(albumId)); @override - Widget onWrap(BuildContext context, Widget child) => PhotosWrapperWidget( + Widget parent(BuildContext context, Widget child) => PhotosWrapperWidget( child: child, ); diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart new file mode 100644 index 00000000..40063f4c --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_profile/blocs/edit_profile_cubit.dart @@ -0,0 +1,74 @@ +// Copyright (C) 2022 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import 'package:example_router/core/constants/form_field.dart'; +import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; +import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; +import 'package:wyatt_type_utils/wyatt_type_utils.dart'; + +class EditProfileCubit extends FormDataCubitImpl { + final AuthenticationRepository authenticationRepository; + + EditProfileCubit( + super._formRepository, + super._formName, { + required this.authenticationRepository, + }) : super(); + + @override + Future submit() async { + emit( + state.copyWith( + status: FormStatus.submissionInProgress, + ), + ); + // final user = (await authenticationRepository.getAccount()).ok; + + final form = state.form; + final email = form.valueOf(AuthFormField.email); + final oldPassword = form.valueOf(AppFormField.oldPassword); + final newPassword = form.valueOf(AuthFormField.password); + + if (email.isNullOrEmpty || + oldPassword.isNullOrEmpty || + newPassword.isNullOrEmpty) { + emit( + state.copyWith( + errorMessage: 'An error occured while retrieving data from the form.', + status: FormStatus.submissionFailure, + ), + ); + } + + try { + // await authenticationRepository.signInWithEmailAndPassword( + // email: user?.email ?? '', + // password: oldPassword ?? '', + // ); + // await authenticationRepository.reauthenticateWithCredential(); + await authenticationRepository.updateEmail(email: email!); + await authenticationRepository.updatePassword(password: newPassword!); + } on Exception catch (e) { + emit( + state.copyWith( + status: FormStatus.submissionFailure, + errorMessage: e.toString(), + ), + ); + } + emit(state.copyWith(status: FormStatus.submissionSuccess)); + } +} diff --git a/packages/wyatt_bloc_helper/example/lib/main.dart b/packages/wyatt_bloc_helper/example/lib/main.dart index a707077c..3d825120 100644 --- a/packages/wyatt_bloc_helper/example/lib/main.dart +++ b/packages/wyatt_bloc_helper/example/lib/main.dart @@ -20,6 +20,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; void main() { - BlocOverrides.runZoned(() => runApp(const CounterRepositoryProviderPage()), - blocObserver: CounterObserver()); + Bloc.observer = CounterObserver(); + runApp(const CounterRepositoryProviderPage()); } diff --git a/packages/wyatt_bloc_layout/example/lib/bloc/example_cubit.dart b/packages/wyatt_bloc_layout/example/lib/bloc/example_cubit.dart index 6ae6a19b..80c20d1a 100644 --- a/packages/wyatt_bloc_layout/example/lib/bloc/example_cubit.dart +++ b/packages/wyatt_bloc_layout/example/lib/bloc/example_cubit.dart @@ -7,24 +7,24 @@ class ExampleCubit extends Cubit { FutureOr run() async { while (true) { - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(CrudLoading()); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(const CrudError('Cubit Error')); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(const CrudLoaded('DATA LOADED')); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(CrudInitial()); } } FutureOr runList() async { while (true) { - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(CrudLoading()); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(const CrudError('Cubit Error')); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit( const CrudListLoaded([ 'DATA LOADED 1', @@ -33,7 +33,7 @@ class ExampleCubit extends Cubit { 'DATA LOADED 4' ]), ); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); emit(CrudInitial()); } } diff --git a/packages/wyatt_form_bloc/example/lib/main.dart b/packages/wyatt_form_bloc/example/lib/main.dart index 42275ce9..28a8f3d9 100644 --- a/packages/wyatt_form_bloc/example/lib/main.dart +++ b/packages/wyatt_form_bloc/example/lib/main.dart @@ -21,10 +21,6 @@ import 'package:form_bloc_example/app/bloc_observer.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - BlocOverrides.runZoned( - () => runApp( - const App(), - ), - blocObserver: AppBlocObserver(), - ); + Bloc.observer = AppBlocObserver(); + runApp(const App()); } diff --git a/packages/wyatt_http_client/example/http_client_example.dart b/packages/wyatt_http_client/example/http_client_example.dart index 3787f1c8..43009540 100644 --- a/packages/wyatt_http_client/example/http_client_example.dart +++ b/packages/wyatt_http_client/example/http_client_example.dart @@ -66,7 +66,7 @@ Future handleDigest(HttpRequest req) async { Future handleUnsafe(HttpRequest req) async { print( 'Query parameters => ' - '${req.uri.queryParameters.toString()}', + '${req.uri.queryParameters}', ); } diff --git a/packages/wyatt_http_client/example/http_client_fastapi_example.dart b/packages/wyatt_http_client/example/http_client_fastapi_example.dart index a671d464..b9a900fd 100644 --- a/packages/wyatt_http_client/example/http_client_fastapi_example.dart +++ b/packages/wyatt_http_client/example/http_client_fastapi_example.dart @@ -82,8 +82,8 @@ class VerifyCode { VerifyCode.fromMap(json.decode(source) as Map); @override - String toString() => - 'VerifyCode(email: $email, verificationCode: $verificationCode, action: $action)'; + String toString() => 'VerifyCode(email: $email, verificationCode: ' + '$verificationCode, action: $action)'; } class Account { @@ -198,8 +198,8 @@ class TokenSuccess { TokenSuccess.fromMap(json.decode(source) as Map); @override - String toString() => - 'TokenSuccess(accessToken: $accessToken, refreshToken: $refreshToken, account: $account)'; + String toString() => 'TokenSuccess(accessToken: $accessToken, refreshToken: ' + '$refreshToken, account: $account)'; } class Login { @@ -353,19 +353,19 @@ void main(List args) async { ); await api.sendSignUpCode('git@pcl.ovh'); - final verifiedAccount = await api.verifyCode( - VerifyCode( - email: 'git@pcl.ovh', - verificationCode: '000000000', - action: EmailVerificationAction.signUp, - ), - ); - final registeredAccount = await api.signUp( - SignUp(sessionId: verifiedAccount.sessionId ?? '', password: 'password'), - ); - final signedInAccount = await api.signInWithPassword( - Login(email: 'git@pcl.ovh', password: 'password'), - ); + // final verifiedAccount = await api.verifyCode( + // VerifyCode( + // email: 'git@pcl.ovh', + // verificationCode: '000000000', + // action: EmailVerificationAction.signUp, + // ), + // ); + // final registeredAccount = await api.signUp( + // SignUp(sessionId: verifiedAccount.sessionId ?? '', password: 'password'), + // ); + // final signedInAccount = await api.signInWithPassword( + // Login(email: 'git@pcl.ovh', password: 'password'), + // ); final accountList = await api.getAccountList(); print(accountList); } diff --git a/packages/wyatt_http_client/example/pipeline.dart b/packages/wyatt_http_client/example/pipeline.dart index 334fc509..7f261f39 100644 --- a/packages/wyatt_http_client/example/pipeline.dart +++ b/packages/wyatt_http_client/example/pipeline.dart @@ -45,7 +45,8 @@ import 'package:wyatt_http_client/src/utils/protocols.dart'; // BaseResponse onResponse(BaseResponse response) { // final res = child?.onResponse(response) ?? response; // print( -// 'RequestMutator::OnResponse: ${res.statusCode} -> ${res.contentLength} bytes', +// 'RequestMutator::OnResponse: ${res.statusCode} -> ${res.contentLength} +// bytes', // ); // return res; // } @@ -75,7 +76,8 @@ import 'package:wyatt_http_client/src/utils/protocols.dart'; // if (response != null) return response; // return Future.sync(() => innerHandler(request)) -// .then((response) => responseHandler!(response), onError: onError); +// .then((response) => responseHandler!(response), onError: +// onError); // }); // }; // }; diff --git a/packages/wyatt_http_client/lib/src/pipeline.dart b/packages/wyatt_http_client/lib/src/pipeline.dart index ae4029ec..3cebc400 100644 --- a/packages/wyatt_http_client/lib/src/pipeline.dart +++ b/packages/wyatt_http_client/lib/src/pipeline.dart @@ -30,6 +30,8 @@ class Pipeline { /// Add a [Middleware] to this [Pipeline] Pipeline addMiddleware(Middleware middleware) { _middlewares.add(middleware); + // TODO(hpcl): use Dart cascades instead of returning this + // ignore: avoid_returning_this return this; }