Register Impl
This commit is contained in:
@@ -1,45 +1,91 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../application/auth/register_form/register_form_bloc.dart';
|
||||
import '../../../../injection.dart';
|
||||
import '../../../components/button/button.dart';
|
||||
import '../../../components/toast/flushbar.dart';
|
||||
import '../../../router/app_router.gr.dart';
|
||||
import 'widgets/birth_date_field.dart';
|
||||
import 'widgets/name_field.dart';
|
||||
import 'widgets/phone_field.dart';
|
||||
|
||||
@RoutePage()
|
||||
class RegisterPage extends StatelessWidget {
|
||||
const RegisterPage({super.key});
|
||||
class RegisterPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
final String phoneNumber;
|
||||
const RegisterPage({super.key, required this.phoneNumber});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Masuk')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 40),
|
||||
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(
|
||||
OtpRoute(registrationToken: data.registrationToken),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
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),
|
||||
|
||||
// Title
|
||||
RegisterPhoneField(),
|
||||
SizedBox(height: 24),
|
||||
RegisterNameField(),
|
||||
RegisterNameField(),
|
||||
SizedBox(height: 24),
|
||||
RegisterBirthDateField(),
|
||||
|
||||
const SizedBox(height: 50),
|
||||
const SizedBox(height: 50),
|
||||
|
||||
Spacer(),
|
||||
Spacer(),
|
||||
|
||||
// Continue Button
|
||||
AppElevatedButton(
|
||||
onPressed: () => context.router.push(const OtpRoute()),
|
||||
title: 'Daftar & Lanjutkan',
|
||||
),
|
||||
// Continue Button
|
||||
AppElevatedButton(
|
||||
onPressed: state.isSubmitting
|
||||
? null
|
||||
: () => context.read<RegisterFormBloc>().add(
|
||||
RegisterFormEvent.submitted(),
|
||||
),
|
||||
title: 'Daftar & Lanjutkan',
|
||||
isLoading: state.isSubmitting,
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<RegisterFormBloc>()
|
||||
..add(RegisterFormEvent.phoneNumberChanged(phoneNumber)),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user