fix(auth): update form plugin and fix auth
This commit is contained in:
@@ -31,23 +31,29 @@ class App extends StatelessWidget {
|
||||
|
||||
static FormData getNormalFormData() {
|
||||
return const FormData([
|
||||
FormEntry(formFieldName, Name.pure()),
|
||||
FormEntry(formFieldPhone, Phone.pure()),
|
||||
FormEntry(formFieldPro, Boolean.pure()),
|
||||
FormEntry(formFieldConfirmedPassword, ConfirmedPassword.pure(),
|
||||
export: false),
|
||||
FormInput(formFieldName, Name.pure()),
|
||||
FormInput(formFieldPhone, Phone.pure()),
|
||||
FormInput(formFieldPro, Boolean.pure()),
|
||||
FormInput(
|
||||
formFieldConfirmedPassword,
|
||||
ConfirmedPassword.pure(),
|
||||
metadata: FormInputMetadata(export: false),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
static FormData getProFormData() {
|
||||
return const FormData([
|
||||
FormEntry(formFieldName, Name.pure()),
|
||||
FormEntry(formFieldPhone, Phone.pure()),
|
||||
FormEntry(formFieldPro, Boolean.pure()),
|
||||
FormEntry(formFieldSiren, Siren.pure()),
|
||||
FormEntry(formFieldIban, Iban.pure()),
|
||||
FormEntry(formFieldConfirmedPassword, ConfirmedPassword.pure(),
|
||||
export: false),
|
||||
FormInput(formFieldName, Name.pure()),
|
||||
FormInput(formFieldPhone, Phone.pure()),
|
||||
FormInput(formFieldPro, Boolean.pure()),
|
||||
FormInput(formFieldSiren, Siren.pure()),
|
||||
FormInput(formFieldIban, Iban.pure()),
|
||||
FormInput(
|
||||
formFieldConfirmedPassword,
|
||||
ConfirmedPassword.pure(),
|
||||
metadata: FormInputMetadata(export: false),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -103,42 +109,42 @@ class App extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
AuthenticationRepositoryInterface _authenticationRepository =
|
||||
AuthenticationRepositoryInterface authenticationRepository =
|
||||
AuthenticationRepositoryFirebase();
|
||||
|
||||
AuthenticationCubit _authenticationCubit = AuthenticationCubit(
|
||||
authenticationRepository: _authenticationRepository,
|
||||
AuthenticationCubit authenticationCubit = AuthenticationCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
onAuthSuccess: onAuthSuccess,
|
||||
);
|
||||
|
||||
SignUpCubit _signUpCubit = SignUpCubit(
|
||||
authenticationRepository: _authenticationRepository,
|
||||
authenticationCubit: _authenticationCubit,
|
||||
SignUpCubit signUpCubit = SignUpCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
entries: getNormalFormData(),
|
||||
onSignUpSuccess: onSignUpSuccess,
|
||||
);
|
||||
|
||||
SignInCubit _signInCubit = SignInCubit(
|
||||
authenticationRepository: _authenticationRepository,
|
||||
authenticationCubit: _authenticationCubit,
|
||||
SignInCubit signInCubit = SignInCubit(
|
||||
authenticationRepository: authenticationRepository,
|
||||
authenticationCubit: authenticationCubit,
|
||||
);
|
||||
|
||||
return MultiRepositoryProvider(
|
||||
providers: [
|
||||
RepositoryProvider<AuthenticationRepositoryInterface>(
|
||||
create: (context) => _authenticationRepository,
|
||||
create: (context) => authenticationRepository,
|
||||
),
|
||||
],
|
||||
child: MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<AuthenticationCubit>(
|
||||
create: (context) => _authenticationCubit..init(),
|
||||
create: (context) => authenticationCubit..init(),
|
||||
),
|
||||
BlocProvider<SignUpCubit>(
|
||||
create: (context) => _signUpCubit,
|
||||
create: (context) => signUpCubit,
|
||||
),
|
||||
BlocProvider<SignInCubit>(
|
||||
create: (context) => _signInCubit,
|
||||
create: (context) => signInCubit,
|
||||
),
|
||||
],
|
||||
child: const AppView(),
|
||||
|
||||
@@ -37,7 +37,7 @@ class _NameInput extends StatelessWidget {
|
||||
labelText: 'name',
|
||||
helperText: '',
|
||||
errorText:
|
||||
state.data.input(formFieldName).invalid ? 'invalid name' : null,
|
||||
state.data.isNotValid(formFieldName) ? 'invalid name' : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -58,7 +58,7 @@ class _PhoneInput extends StatelessWidget {
|
||||
decoration: InputDecoration(
|
||||
labelText: 'phone',
|
||||
helperText: '',
|
||||
errorText: state.data.input(formFieldPhone).invalid
|
||||
errorText: state.data.isNotValid(formFieldPhone)
|
||||
? 'invalid phone'
|
||||
: null,
|
||||
),
|
||||
@@ -81,7 +81,7 @@ class _SirenInput extends StatelessWidget {
|
||||
decoration: InputDecoration(
|
||||
labelText: 'siren',
|
||||
helperText: '',
|
||||
errorText: state.data.input(formFieldSiren).invalid
|
||||
errorText: state.data.isNotValid(formFieldSiren)
|
||||
? 'invalid SIREN'
|
||||
: null,
|
||||
),
|
||||
@@ -105,7 +105,7 @@ class _IbanInput extends StatelessWidget {
|
||||
labelText: 'iban',
|
||||
helperText: '',
|
||||
errorText:
|
||||
state.data.input(formFieldIban).invalid ? 'invalid IBAN' : null,
|
||||
state.data.isNotValid(formFieldIban) ? 'invalid IBAN' : null,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -149,8 +149,7 @@ class _PasswordInput extends StatelessWidget {
|
||||
.read<SignUpCubit>()
|
||||
.state
|
||||
.data
|
||||
.input(formFieldConfirmedPassword)
|
||||
.value,
|
||||
.valueOf<String, ValidationError>(formFieldConfirmedPassword),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -185,7 +184,7 @@ class _ConfirmPasswordInput extends StatelessWidget {
|
||||
decoration: InputDecoration(
|
||||
labelText: 'confirm password',
|
||||
helperText: '',
|
||||
errorText: state.data.input(formFieldConfirmedPassword).invalid
|
||||
errorText: state.data.isNotValid(formFieldConfirmedPassword)
|
||||
? 'passwords do not match'
|
||||
: null,
|
||||
),
|
||||
@@ -203,7 +202,7 @@ class _CheckIsProInput extends StatelessWidget {
|
||||
trailing: BlocBuilder<SignUpCubit, SignUpState>(
|
||||
builder: (context, state) {
|
||||
return Checkbox(
|
||||
value: state.data.input<bool>(formFieldPro).value,
|
||||
value: state.data.valueOf<bool, ValidationError>(formFieldPro),
|
||||
onChanged: (isPro) {
|
||||
final value =
|
||||
isPro!; // tristate is false, so value can't be null
|
||||
@@ -297,7 +296,7 @@ class SignUpForm extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
BlocBuilder<SignUpCubit, SignUpState>(
|
||||
builder: (context, state) {
|
||||
if (state.data.input<bool>(formFieldPro).value) {
|
||||
if (state.data.valueOf<bool, ValidationError>(formFieldPro)) {
|
||||
return Column(children: [
|
||||
_SirenInput(),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
Reference in New Issue
Block a user