From 1de922f6446be06628025264065101c80bd59027 Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Mon, 6 Feb 2023 21:24:00 +0100 Subject: [PATCH] docs(authentication): update example --- .../example/lib/core/constants/form_name.dart | 19 --- .../example/lib/core/routes/router.dart | 14 +- .../lib/presentation/features/app/app.dart | 23 +-- .../sign_in/blocs/sign_in_cubit.dart} | 20 +-- .../sign_in/sign_in_page.dart | 2 +- .../sign_in/widgets/sign_in_form.dart | 28 ++-- .../sign_up/blocs/sign_up_cubit.dart} | 23 +-- .../sign_up/sign_up_page.dart | 2 +- .../sign_up/widgets/sign_up_form.dart | 34 ++-- .../blocs/edit_account_cubit.dart} | 32 ++-- .../edit_account/edit_account_page.dart} | 23 ++- .../widgets/edit_account_form.dart | 151 ++++++++++++++++++ .../presentation/features/home/home_page.dart | 48 +++--- .../features/welcome/welcome_page.dart | 24 +-- 14 files changed, 302 insertions(+), 141 deletions(-) delete mode 100644 packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{sign_in/blocs/custom_sign_in_cubit.dart => authentication/sign_in/blocs/sign_in_cubit.dart} (62%) rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{ => authentication}/sign_in/sign_in_page.dart (91%) rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{ => authentication}/sign_in/widgets/sign_in_form.dart (89%) rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{sign_up/blocs/custom_sign_up_cubit.dart => authentication/sign_up/blocs/sign_up_cubit.dart} (64%) rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{ => authentication}/sign_up/sign_up_page.dart (91%) rename packages/wyatt_authentication_bloc/example/lib/presentation/features/{ => authentication}/sign_up/widgets/sign_up_form.dart (85%) rename packages/wyatt_authentication_bloc/example/lib/{core/utils/forms.dart => presentation/features/edit_account/blocs/edit_account_cubit.dart} (58%) rename packages/wyatt_authentication_bloc/example/lib/{core/constants/form_field.dart => presentation/features/edit_account/edit_account_page.dart} (54%) create mode 100644 packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/widgets/edit_account_form.dart diff --git a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart b/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart deleted file mode 100644 index 1ff68488..00000000 --- a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_name.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2023 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 . - -abstract class AppFormName { - static const editProfile = 'editProfile'; -} diff --git a/packages/wyatt_authentication_bloc/example/lib/core/routes/router.dart b/packages/wyatt_authentication_bloc/example/lib/core/routes/router.dart index dea8429c..f38047f3 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/routes/router.dart +++ b/packages/wyatt_authentication_bloc/example/lib/core/routes/router.dart @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:example_router/presentation/features/authentication/sign_in/sign_in_page.dart'; +import 'package:example_router/presentation/features/authentication/sign_up/sign_up_page.dart'; +import 'package:example_router/presentation/features/edit_account/edit_account_page.dart'; import 'package:example_router/presentation/features/home/home_page.dart'; -import 'package:example_router/presentation/features/sign_in/sign_in_page.dart'; -import 'package:example_router/presentation/features/sign_up/sign_up_page.dart'; import 'package:example_router/presentation/features/sub/sub_page.dart'; import 'package:example_router/presentation/features/welcome/welcome_page.dart'; import 'package:flutter/cupertino.dart'; @@ -82,6 +83,15 @@ class AppRouter { const SubPage(), ), ), + GoRoute( + path: 'edit_account', + name: EditAccountPage.pageName, + pageBuilder: (context, state) => defaultTransition( + context, + state, + const EditAccountPage(), + ), + ), ]), ]; } diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart index 75388b5e..5285f63d 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/app/app.dart @@ -16,14 +16,13 @@ import 'dart:async'; -import 'package:example_router/core/constants/form_field.dart'; import 'package:example_router/core/dependency_injection/get_it.dart'; import 'package:example_router/core/routes/router.dart'; import 'package:example_router/core/utils/custom_password.dart'; -import 'package:example_router/core/utils/forms.dart'; import 'package:example_router/presentation/features/authentication/authentication_cubit.dart'; -import 'package:example_router/presentation/features/sign_in/blocs/custom_sign_in_cubit.dart'; -import 'package:example_router/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart'; +import 'package:example_router/presentation/features/authentication/sign_in/blocs/sign_in_cubit.dart'; +import 'package:example_router/presentation/features/authentication/sign_up/blocs/sign_up_cubit.dart'; +import 'package:example_router/presentation/features/edit_account/blocs/edit_account_cubit.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; @@ -38,7 +37,7 @@ class App extends StatelessWidget { customPasswordValidator: const CustomPassword.pure(), extraSignUpInputs: [ FormInput( - AppFormField.confirmedPassword, + AuthFormField.confirmPassword, const ConfirmedPassword.pure(), metadata: const FormInputMetadata(export: false), ), @@ -90,9 +89,8 @@ class App extends StatelessWidget { value: authenticationRepository, ), RepositoryProvider( - create: (context) => - FormRepositoryImpl()..registerForm(AppForms.getEditProfileForm()), - ), + create: (context) => FormRepositoryImpl(), + ) ], child: MultiBlocProvider( providers: [ @@ -100,12 +98,17 @@ class App extends StatelessWidget { value: authenticationCubit, ), BlocProvider>( - create: (_) => CustomSignUpCubit( + create: (_) => ExampleSignUpCubit( authenticationRepository: authenticationRepository, ), ), BlocProvider>( - create: (_) => CustomSignInCubit( + create: (_) => ExampleSignInCubit( + authenticationRepository: authenticationRepository, + ), + ), + BlocProvider>( + create: (_) => ExampleEditAccountCubit( authenticationRepository: authenticationRepository, ), ), diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/blocs/custom_sign_in_cubit.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/blocs/sign_in_cubit.dart similarity index 62% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/blocs/custom_sign_in_cubit.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/blocs/sign_in_cubit.dart index 882cfd35..947295c2 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/blocs/custom_sign_in_cubit.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/blocs/sign_in_cubit.dart @@ -14,33 +14,35 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:wyatt_architecture/src/domain/usecases/usecase.dart'; -import 'package:wyatt_architecture/src/core/exceptions/exceptions.dart'; +import 'package:wyatt_architecture/wyatt_architecture.dart'; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; -import 'package:wyatt_type_utils/src/either/either_base.dart'; -import 'package:wyatt_form_bloc/src/domain/form/wyatt_form.dart'; +import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; +import 'package:wyatt_type_utils/wyatt_type_utils.dart'; -class CustomSignInCubit extends SignInCubit { - CustomSignInCubit({ +class ExampleSignInCubit extends SignInCubit { + ExampleSignInCubit({ required super.authenticationRepository, }); @override - FutureOrResult onSignInWithEmailAndPassword(Result result, WyattForm form) { + FutureOrResult onSignInWithEmailAndPassword( + Result result, WyattForm form) { print('onSignInWithEmailAndPassword'); return const Ok(1); } @override - FutureOrResult onSignInAnonymously(Result result, WyattForm form) { + FutureOrResult onSignInAnonymously( + Result result, WyattForm form) { print('onSignInAnonymously'); return const Ok(1); } @override - FutureOrResult onSignInWithGoogle(Result result, WyattForm form) { + FutureOrResult onSignInWithGoogle( + Result result, WyattForm form) { print('onSignInWithGoogle'); return const Ok(1); diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/sign_in_page.dart similarity index 91% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/sign_in_page.dart index 5ac3770b..5294fed0 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/sign_in_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/sign_in_page.dart @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:example_router/presentation/features/sign_in/widgets/sign_in_form.dart'; +import 'package:example_router/presentation/features/authentication/sign_in/widgets/sign_in_form.dart'; import 'package:flutter/material.dart'; class SignInPage extends StatelessWidget { diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/widgets/sign_in_form.dart similarity index 89% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/widgets/sign_in_form.dart index bf39991c..ebb65583 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_in/widgets/sign_in_form.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_in/widgets/sign_in_form.dart @@ -121,21 +121,19 @@ class SignInForm extends StatelessWidget { ..showSnackBar( SnackBar(content: Text(errorMessage ?? 'Sign In Failure')), ), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - _EmailInput(), - const SizedBox(height: 8), - _PasswordInput(), - const SizedBox(height: 16), - _SignInButton(), - const SizedBox(height: 16), - _SignInAnonymouslyButton(), - const SizedBox(height: 16), - _SignInWithGoogleButton(), - ], - ), + child: ListView( + shrinkWrap: true, + children: [ + _EmailInput(), + const SizedBox(height: 8), + _PasswordInput(), + const SizedBox(height: 16), + _SignInButton(), + const SizedBox(height: 16), + _SignInAnonymouslyButton(), + const SizedBox(height: 16), + _SignInWithGoogleButton(), + ], ), ); } diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/blocs/sign_up_cubit.dart similarity index 64% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/blocs/sign_up_cubit.dart index d49e6056..3f5bb9a1 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/blocs/custom_sign_up_cubit.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/blocs/sign_up_cubit.dart @@ -14,34 +14,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - import 'package:wyatt_architecture/wyatt_architecture.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 CustomSignUpCubit extends SignUpCubit { - CustomSignUpCubit({ +class ExampleSignUpCubit extends SignUpCubit { + ExampleSignUpCubit({ required super.authenticationRepository, }); - - @override - FutureOrResult onSignUpWithEmailAndPassword(Result result, WyattForm form) async { - // if (result.isOk) { - // await Future.delayed(const Duration(seconds: 3)); - // const id = -1; - // final confirmedPassword = - // form.valueOf(AppFormField.confirmedPassword); - // debugPrint( - // 'onSignUpSuccess: ${result.ok}, generatedId: $id, intFormData: $confirmedPassword'); - // return const Ok(id); - // } - // return const Ok(null); + @override + FutureOrResult onSignUpWithEmailAndPassword( + Result result, WyattForm form) async { print('onSignUpWithEmailAndPassword'); return const Ok(1); } - - } diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/sign_up_page.dart similarity index 91% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/sign_up_page.dart index 2f0f6ce5..d9963142 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/sign_up_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/sign_up_page.dart @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:example_router/presentation/features/sign_up/widgets/sign_up_form.dart'; +import 'package:example_router/presentation/features/authentication/sign_up/widgets/sign_up_form.dart'; import 'package:flutter/material.dart'; class SignUpPage extends StatelessWidget { diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/widgets/sign_up_form.dart similarity index 85% rename from packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/widgets/sign_up_form.dart index 23b9884d..4c13a491 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/sign_up/widgets/sign_up_form.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/authentication/sign_up/widgets/sign_up_form.dart @@ -14,7 +14,6 @@ // 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:example_router/core/utils/custom_password.dart'; import 'package:flutter/material.dart' hide FormField; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; @@ -51,11 +50,11 @@ class _PasswordInput extends StatelessWidget { cubit.passwordCustomChanged( CustomPassword.dirty(pwd)); cubit.dataChanged( - AppFormField.confirmedPassword, + AuthFormField.confirmPassword, ConfirmedPassword.dirty( password: pwd, value: state.form - .valueOf(AppFormField.confirmedPassword))); + .valueOf(AuthFormField.confirmPassword))); }, obscureText: true, decoration: InputDecoration( @@ -73,7 +72,7 @@ class _ConfirmPasswordInput extends StatelessWidget { @override Widget build(BuildContext context) { return InputBuilder>( - field: AppFormField.confirmedPassword, + field: AuthFormField.confirmPassword, builder: ((context, cubit, state, field, input) { return TextField( onChanged: (pwd) { @@ -106,7 +105,9 @@ class _SignUpButton extends StatelessWidget { return status.isSubmissionInProgress ? const CircularProgressIndicator() : ElevatedButton( - onPressed: status.isValidated ? () => cubit.signUpWithEmailPassword() : null, + onPressed: status.isValidated + ? () => cubit.signUpWithEmailPassword() + : null, child: const Text('Sign up'), ); }), @@ -126,18 +127,17 @@ class SignUpForm extends StatelessWidget { ..showSnackBar( SnackBar(content: Text(errorMessage ?? 'Sign Up Failure')), ), - child: SingleChildScrollView( - child: Column( - children: [ - _EmailInput(), - const SizedBox(height: 8), - _PasswordInput(), - const SizedBox(height: 8), - _ConfirmPasswordInput(), - const SizedBox(height: 16), - _SignUpButton(), - ], - ), + child: ListView( + shrinkWrap: true, + children: [ + _EmailInput(), + const SizedBox(height: 8), + _PasswordInput(), + const SizedBox(height: 8), + _ConfirmPasswordInput(), + const SizedBox(height: 16), + _SignUpButton(), + ], )); } } diff --git a/packages/wyatt_authentication_bloc/example/lib/core/utils/forms.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/blocs/edit_account_cubit.dart similarity index 58% rename from packages/wyatt_authentication_bloc/example/lib/core/utils/forms.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/blocs/edit_account_cubit.dart index 49fdfa9a..1a5d2b8c 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/utils/forms.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/blocs/edit_account_cubit.dart @@ -14,19 +14,27 @@ // 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:example_router/core/constants/form_name.dart'; -import 'package:example_router/core/utils/custom_password.dart'; +import 'package:wyatt_architecture/wyatt_architecture.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'; -abstract class AppForms { - static WyattForm getEditProfileForm() => WyattFormImpl( - [ - FormInput(AuthFormField.email, const Email.pure()), - FormInput(AuthFormField.password, const CustomPassword.pure()), - FormInput(AppFormField.oldPassword, const CustomPassword.pure()), - ], - name: AppFormName.editProfile, - ); +class ExampleEditAccountCubit extends EditAccountCubit { + ExampleEditAccountCubit({required super.authenticationRepository}); + + @override + FutureOrResult onEmailUpdated( + Result result, WyattForm form) async { + print('onEmailUpdated'); + + return const Ok(1); + } + + @override + FutureOrResult onPasswordUpdated( + Result result, WyattForm form) async { + print('onPasswordUpdated'); + + return const Ok(1); + } } diff --git a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/edit_account_page.dart similarity index 54% rename from packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.dart rename to packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/edit_account_page.dart index d111abaf..11b0f987 100644 --- a/packages/wyatt_authentication_bloc/example/lib/core/constants/form_field.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/edit_account_page.dart @@ -14,7 +14,24 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -abstract class AppFormField { - static const oldPassword = 'oldPassword'; - static const confirmedPassword = 'confirmedPassword'; +import 'package:example_router/presentation/features/edit_account/widgets/edit_account_form.dart'; +import 'package:flutter/material.dart'; + +class EditAccountPage extends StatelessWidget { + const EditAccountPage({Key? key}) : super(key: key); + + static String pageName = 'EditAccount'; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Edit Account')), + body: const Padding( + padding: EdgeInsets.all(8), + child: SingleChildScrollView( + child: EditAccountForm(), + ), + ), + ); + } } diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/widgets/edit_account_form.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/widgets/edit_account_form.dart new file mode 100644 index 00000000..c80439a9 --- /dev/null +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/edit_account/widgets/edit_account_form.dart @@ -0,0 +1,151 @@ +// Copyright (C) 2023 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/utils/custom_password.dart'; +import 'package:flutter/material.dart'; +import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; +import 'package:wyatt_form_bloc/wyatt_form_bloc.dart'; + +class _EmailInput extends StatelessWidget { + @override + Widget build(BuildContext context) { + return InputBuilder>( + field: AuthFormField.email, + builder: ((context, cubit, state, field, input) { + return TextField( + onChanged: (email) => cubit.emailChanged(email), + keyboardType: TextInputType.emailAddress, + decoration: InputDecoration( + labelText: 'Email', + helperText: '', + errorText: input.validator.invalid ? 'Invalid email' : null, + ), + ); + }), + ); + } +} + +class _PasswordInput extends StatelessWidget { + @override + Widget build(BuildContext context) { + return InputBuilder>( + field: AuthFormField.password, + builder: ((context, cubit, state, field, input) { + return TextField( + onChanged: (pwd) => cubit + .passwordCustomChanged(CustomPassword.dirty(pwd)), + obscureText: true, + decoration: InputDecoration( + labelText: 'Password', + helperText: '', + errorText: input.validator.invalid ? 'Invalid password' : null, + ), + ); + }), + ); + } +} + +class _EditAccountButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return SubmitBuilder>( + builder: ((context, cubit, status) { + return status.isSubmissionInProgress + ? const CircularProgressIndicator() + : ElevatedButton( + onPressed: status.isValidated + ? () { + cubit.updateEmail(); + cubit.updatePassword(); + } + : null, + child: const Text('Update Account'), + ); + }), + ); + } +} + +class _EditAccountEmailButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return SubmitBuilder>( + builder: ((context, cubit, status) { + return status.isSubmissionInProgress + ? const CircularProgressIndicator() + : ElevatedButton( + onPressed: status.isValidated + ? () { + cubit.updateEmail(); + } + : null, + child: const Text('Update Account Email'), + ); + }), + ); + } +} + +class _EditAccountPasswordButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return SubmitBuilder>( + builder: ((context, cubit, status) { + return status.isSubmissionInProgress + ? const CircularProgressIndicator() + : ElevatedButton( + onPressed: status.isValidated + ? () { + cubit.updatePassword(); + } + : null, + child: const Text('Update Account Password'), + ); + }), + ); + } +} + +class EditAccountForm extends StatelessWidget { + const EditAccountForm({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return EditAccountListener( + onError: (context, status, errorMessage) => ScaffoldMessenger.of(context) + ..hideCurrentSnackBar() + ..showSnackBar( + SnackBar(content: Text(errorMessage ?? 'Account edition Failure')), + ), + child: ListView( + shrinkWrap: true, + children: [ + _EmailInput(), + const SizedBox(height: 8), + _PasswordInput(), + const SizedBox(height: 16), + _EditAccountButton(), + const SizedBox(height: 16), + _EditAccountEmailButton(), + const SizedBox(height: 16), + _EditAccountPasswordButton(), + ], + ), + ); + } +} diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/home/home_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/home/home_page.dart index a66a38a0..dade25b8 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/home/home_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/home/home_page.dart @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +import 'package:example_router/presentation/features/edit_account/edit_account_page.dart'; import 'package:example_router/presentation/features/sub/sub_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -29,7 +30,8 @@ class HomePage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('Home | ${context.account, int>()?.email}'), + title: Text( + 'Home | ${context.account, int>()?.email}'), actions: [ IconButton( onPressed: () => @@ -39,29 +41,27 @@ class HomePage extends StatelessWidget { ), body: Padding( padding: const EdgeInsets.all(8), - child: SingleChildScrollView( - child: Column( - children: [ - AuthenticationBuilder( - authenticated: (context, sessionWrapper) => Text( - 'Logged as ${sessionWrapper.session?.account.email} | GeneratedId is ${sessionWrapper.session?.data}'), - unauthenticated: (context) => - const Text('Not logged (unauthenticated)'), - unknown: (context) => const Text('Not logged (unknown)'), - ), - const SizedBox( - height: 8, - ), - ElevatedButton( - onPressed: () => context.pushNamed(SubPage.pageName), - child: const Text('Go to sub page'), - ), - // ElevatedButton( - // onPressed: () => context.pushNamed(EditProfilePage.pageName), - // child: const Text('Go to edit profile page'), - // ), - ], - ), + child: ListView( + children: [ + AuthenticationBuilder( + authenticated: (context, sessionWrapper) => Text( + 'Logged as ${sessionWrapper.session?.account.email} | GeneratedId is ${sessionWrapper.session?.data}'), + unauthenticated: (context) => + const Text('Not logged (unauthenticated)'), + unknown: (context) => const Text('Not logged (unknown)'), + ), + const SizedBox( + height: 8, + ), + ElevatedButton( + onPressed: () => context.pushNamed(SubPage.pageName), + child: const Text('Go to sub page'), + ), + ElevatedButton( + onPressed: () => context.pushNamed(EditAccountPage.pageName), + child: const Text('Go to edit account page'), + ), + ], ), ), ); diff --git a/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart b/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart index 29e97aa4..2d2ab4bc 100644 --- a/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart +++ b/packages/wyatt_authentication_bloc/example/lib/presentation/features/welcome/welcome_page.dart @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import 'package:example_router/presentation/features/sign_in/sign_in_page.dart'; -import 'package:example_router/presentation/features/sign_up/sign_up_page.dart'; +import 'package:example_router/presentation/features/authentication/sign_in/sign_in_page.dart'; +import 'package:example_router/presentation/features/authentication/sign_up/sign_up_page.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -30,22 +30,26 @@ class WelcomePage extends StatelessWidget { appBar: AppBar( title: const Text('Welcome'), ), - body: SingleChildScrollView( - child: Column( - children: [ - ElevatedButton( + body: ListView( + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( onPressed: () => context.pushNamed(SignUpPage.pageName), child: const Text('Sign Up')), - ElevatedButton( + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( onPressed: () => context.pushNamed(SignInPage.pageName), style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.white), foregroundColor: MaterialStateProperty.all(Colors.blue)), - child: const Text('Sign In')) - ], - ), + child: const Text('Sign In')), + ) + ], ), ); }