Register Impl
This commit is contained in:
@@ -33,7 +33,9 @@ class LoginPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
Future.delayed(Duration(milliseconds: 1000), () {
|
||||
log(data.toString());
|
||||
if (data.status.isNotRegistered) {
|
||||
context.router.push(RegisterRoute());
|
||||
context.router.push(
|
||||
RegisterRoute(phoneNumber: data.phoneNumber),
|
||||
);
|
||||
} else if (data.status.isPasswordRequired) {
|
||||
context.router.push(
|
||||
PasswordRoute(
|
||||
|
||||
@@ -8,7 +8,8 @@ import '../../../router/app_router.gr.dart';
|
||||
|
||||
@RoutePage()
|
||||
class OtpPage extends StatefulWidget {
|
||||
const OtpPage({super.key});
|
||||
final String registrationToken;
|
||||
const OtpPage({super.key, required this.registrationToken});
|
||||
|
||||
@override
|
||||
State<OtpPage> createState() => _OtpPageState();
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../application/auth/register_form/register_form_bloc.dart';
|
||||
import '../../../../components/field/field.dart';
|
||||
|
||||
class RegisterBirthDateField extends StatelessWidget {
|
||||
const RegisterBirthDateField({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DatePickerField(
|
||||
label: 'Masukkan tanggal lahir',
|
||||
onDateSelected: (value) {
|
||||
context.read<RegisterFormBloc>().add(
|
||||
RegisterFormEvent.birthDateChanged(value),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../application/auth/register_form/register_form_bloc.dart';
|
||||
import '../../../../components/field/field.dart';
|
||||
|
||||
class RegisterNameField extends StatelessWidget {
|
||||
@@ -7,6 +9,21 @@ class RegisterNameField extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppTextFormField(title: 'Masukkan nama', hintText: 'John Doe');
|
||||
return AppTextFormField(
|
||||
title: 'Masukkan nama',
|
||||
hintText: 'John Doe',
|
||||
onChanged: (value) {
|
||||
context.read<RegisterFormBloc>().add(
|
||||
RegisterFormEvent.nameChanged(value),
|
||||
);
|
||||
},
|
||||
validator: (value) {
|
||||
if (context.read<RegisterFormBloc>().state.name.isEmpty) {
|
||||
return 'Masukkan nama';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../common/theme/theme.dart';
|
||||
import '../../../../components/field/field.dart';
|
||||
|
||||
class RegisterPhoneField extends StatefulWidget {
|
||||
const RegisterPhoneField({super.key});
|
||||
|
||||
@override
|
||||
State<RegisterPhoneField> createState() => _RegisterPhoneFieldState();
|
||||
}
|
||||
|
||||
class _RegisterPhoneFieldState extends State<RegisterPhoneField> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
bool _hasFocus = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode.addListener(() {
|
||||
setState(() {
|
||||
_hasFocus = _focusNode.hasFocus;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _clearText() {
|
||||
_controller.clear();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppTextFormField(
|
||||
title: 'Masukkan no telepon',
|
||||
hintText: '8712671212',
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
keyboardType: TextInputType.phone,
|
||||
prefixIcon: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Text(
|
||||
'+62',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: AppColor.textPrimary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
suffixIcon: (_hasFocus && _controller.text.isNotEmpty)
|
||||
? IconButton(
|
||||
onPressed: _clearText,
|
||||
icon: Icon(Icons.close, color: AppColor.primary, size: 20),
|
||||
constraints: const BoxConstraints(),
|
||||
padding: const EdgeInsets.all(8),
|
||||
)
|
||||
: null,
|
||||
onChanged: (value) {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user