fix: add validation submit sign in

This commit is contained in:
2024-02-20 15:38:21 +07:00
parent e510aaefd7
commit c4c0479341
4 changed files with 190 additions and 162 deletions

View File

@@ -10,70 +10,83 @@ import 'package:provider/provider.dart';
class PasswordView extends StatelessWidget {
final void Function() nextStep;
final TextEditingController controller;
const PasswordView({super.key, required this.nextStep, required this.controller});
const PasswordView(
{super.key, required this.nextStep, required this.controller});
@override
Widget build(BuildContext context) {
return Consumer<LoginViewModel>(
builder: (context, provider, child) {
return Container(
width: SizeConfig.width,
height: SizeConfig.height,
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TextTitle(title: 'Enter your password', fontSize: 24),
SizedBox(
height: 24,
),
TextFormView(
name: 'Password',
ctrl: controller,
obscureText: !provider.showPassword,
contentPadding: EdgeInsets.all(12),
suffixIcon: GestureDetector(
onTap: () {
provider.changeShowPassword();
return Consumer<LoginViewModel>(builder: (context, provider, child) {
return Container(
width: SizeConfig.width,
height: SizeConfig.height,
padding: const EdgeInsets.all(24),
child: Form(
key: provider.formKey,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TextTitle(title: 'Enter your password', fontSize: 24),
SizedBox(
height: 24,
),
TextFormView(
name: 'Password',
ctrl: controller,
obscureText: !provider.showPassword,
contentPadding: EdgeInsets.all(12),
validator: (value) {
if (value!.isEmpty) {
return 'Password must filled';
} else if (value.length < 8) {
return 'Minimum password 8 Character';
} else {
return null;
}
},
child: Icon(
provider.showPassword
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
color: ColorPalette.greyDarker,
suffixIcon: GestureDetector(
onTap: () {
provider.changeShowPassword();
},
child: Icon(
provider.showPassword
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
color: ColorPalette.greyDarker,
),
),
),
),
TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(0)
TextButton(
style: TextButton.styleFrom(padding: EdgeInsets.all(0)),
onPressed: () {},
child: Text(
'Forget the password?',
style: TextStyle(
color: ColorPalette.primary,
),
)),
SizedBox(
height: 16,
),
onPressed: () {
},
child: Text(
'Forget the password?',
style: TextStyle(
color: ColorPalette.primary,
),
ButtonView(
name: 'Confirm',
heightWrapContent: true,
width: SizeConfig.width,
textSize: 18,
marginVertical: 0,
contentPadding:
EdgeInsets.symmetric(horizontal: 16, vertical: 12),
onPressed: () {
if (provider.formKey.currentState!.validate()) {
nextStep();
}
},
)
),
SizedBox(
height: 16,
),
ButtonView(
name: 'Confirm',
heightWrapContent: true,
width: SizeConfig.width,
textSize: 18,
marginVertical: 0,
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
onPressed: nextStep,
)
],
],
),
),
);
}
);
),
);
});
}
}