Set Password

This commit is contained in:
efrilm
2025-09-18 09:17:25 +07:00
parent 8e35582f93
commit 2e00207343
5 changed files with 170 additions and 40 deletions
@@ -1,50 +1,134 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../application/auth/set_password/set_password_form_bloc.dart';
import '../../../../injection.dart';
import '../../../components/button/button.dart';
import '../../../components/field/field.dart';
import '../../../components/toast/flushbar.dart';
import '../../../router/app_router.gr.dart';
@RoutePage()
class CreatePasswordPage extends StatelessWidget {
const CreatePasswordPage({super.key});
class CreatePasswordPage extends StatelessWidget implements AutoRouteWrapper {
final String registrationToken;
const CreatePasswordPage({super.key, required this.registrationToken});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Buat Kata Sandi')),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40),
return BlocListener<SetPasswordFormBloc, SetPasswordFormState>(
listenWhen: (p, c) =>
p.failureOrSetPasswordOption != c.failureOrSetPasswordOption,
listener: (context, state) {
state.failureOrSetPasswordOption.fold(
() => null,
(either) => either.fold(
(f) => AppFlushbar.showAuthFailureToast(context, f),
(data) {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.replaceAll([MainRoute()]);
});
},
),
);
},
child: Scaffold(
appBar: AppBar(title: const Text('Buat Kata Sandi')),
body: BlocBuilder<SetPasswordFormBloc, SetPasswordFormState>(
builder: (context, state) {
return Form(
autovalidateMode: state.showErrorMessages
? AutovalidateMode.always
: AutovalidateMode.disabled,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40),
// Title
AppPasswordTextFormField(
title: 'Masukkan kata sandi',
hintText: '********',
),
SizedBox(height: 24),
AppPasswordTextFormField(
title: 'Ulangi kata sandi',
hintText: '********',
),
// Title
AppPasswordTextFormField(
title: 'Masukkan kata sandi',
hintText: '********',
onChanged: (value) => context
.read<SetPasswordFormBloc>()
.add(SetPasswordFormEvent.passwordChanged(value)),
validator: (value) {
if (context
.read<SetPasswordFormBloc>()
.state
.password
.isEmpty) {
return 'Masukkan kata sandi';
}
const SizedBox(height: 50),
return null;
},
),
SizedBox(height: 24),
AppPasswordTextFormField(
title: 'Ulangi kata sandi',
hintText: '********',
onChanged: (value) =>
context.read<SetPasswordFormBloc>().add(
SetPasswordFormEvent.confirmPasswordChanged(value),
),
validator: (value) {
if (context
.read<SetPasswordFormBloc>()
.state
.password
.isEmpty) {
return 'Masukkan kata sandi';
}
Spacer(),
if (context
.read<SetPasswordFormBloc>()
.state
.password !=
context
.read<SetPasswordFormBloc>()
.state
.confirmPassword) {
return 'Kata sandi tidak cocok';
}
// Continue Button
AppElevatedButton(
onPressed: () => context.router.push(const MainRoute()),
title: 'Konfirmasi',
),
return null;
},
),
const SizedBox(height: 24),
],
const SizedBox(height: 50),
Spacer(),
// Continue Button
AppElevatedButton(
onPressed: state.isSubmitting
? null
: () => context.read<SetPasswordFormBloc>().add(
SetPasswordFormEvent.submitted(),
),
title: 'Konfirmasi',
isLoading: state.isSubmitting,
),
const SizedBox(height: 24),
],
),
),
);
},
),
),
);
}
@override
Widget wrappedRoute(BuildContext context) => BlocProvider(
create: (context) => getIt<SetPasswordFormBloc>()
..add(SetPasswordFormEvent.registrationTokenChanged(registrationToken)),
child: this,
);
}
+15 -4
View File
@@ -143,10 +143,21 @@ class _OtpPageState extends State<OtpPage> {
(either) => either.fold(
(f) => AppFlushbar.showAuthFailureToast(context, f),
(data) {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.push(CreatePasswordRoute());
});
if (data.status == "FAILED") {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.replaceAll([LoginRoute()]);
});
} else {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.push(
CreatePasswordRoute(
registrationToken: widget.registrationToken,
),
);
});
}
},
),
);