95 lines
3.1 KiB
Dart
Raw Normal View History

2025-08-27 17:11:38 +07:00
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
2025-09-18 08:48:36 +07:00
import 'package:flutter_bloc/flutter_bloc.dart';
2025-08-27 17:11:38 +07:00
2025-09-18 08:48:36 +07:00
import '../../../../application/auth/register_form/register_form_bloc.dart';
import '../../../../injection.dart';
2025-08-27 17:11:38 +07:00
import '../../../components/button/button.dart';
2025-09-18 08:48:36 +07:00
import '../../../components/toast/flushbar.dart';
2025-08-27 17:34:35 +07:00
import '../../../router/app_router.gr.dart';
2025-09-18 08:48:36 +07:00
import 'widgets/birth_date_field.dart';
2025-08-27 17:11:38 +07:00
import 'widgets/name_field.dart';
@RoutePage()
2025-09-18 08:48:36 +07:00
class RegisterPage extends StatelessWidget implements AutoRouteWrapper {
final String phoneNumber;
const RegisterPage({super.key, required this.phoneNumber});
2025-08-27 17:11:38 +07:00
@override
Widget build(BuildContext context) {
2025-09-18 08:48:36 +07:00
return BlocListener<RegisterFormBloc, RegisterFormState>(
listenWhen: (p, c) =>
p.failureOrRegisterOption != c.failureOrRegisterOption,
listener: (context, state) {
state.failureOrRegisterOption.fold(
() {},
(either) => either.fold(
(f) => AppFlushbar.showAuthFailureToast(context, f),
(data) {
AppFlushbar.showSuccess(context, data.message);
Future.delayed(Duration(milliseconds: 1000), () {
context.router.push(
2025-09-18 09:03:50 +07:00
OtpRoute(
registrationToken: data.registrationToken,
phoneNumber: phoneNumber,
),
2025-09-18 08:48:36 +07:00
);
});
},
),
);
},
child: Scaffold(
appBar: AppBar(title: const Text('Daftar')),
body: BlocBuilder<RegisterFormBloc, RegisterFormState>(
builder: (context, state) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Form(
autovalidateMode: state.showErrorMessages
? AutovalidateMode.always
: AutovalidateMode.disabled,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40),
RegisterNameField(),
SizedBox(height: 24),
RegisterBirthDateField(),
const SizedBox(height: 50),
Spacer(),
// Continue Button
AppElevatedButton(
onPressed: state.isSubmitting
? null
: () => context.read<RegisterFormBloc>().add(
RegisterFormEvent.submitted(),
),
title: 'Daftar & Lanjutkan',
isLoading: state.isSubmitting,
),
const SizedBox(height: 24),
],
),
),
);
},
2025-08-27 17:11:38 +07:00
),
),
);
}
2025-09-18 08:48:36 +07:00
@override
Widget wrappedRoute(BuildContext context) => BlocProvider(
create: (context) =>
getIt<RegisterFormBloc>()
..add(RegisterFormEvent.phoneNumberChanged(phoneNumber)),
child: this,
);
2025-08-27 17:11:38 +07:00
}