2025-09-18 08:01:49 +07:00
|
|
|
import 'dart:developer';
|
|
|
|
|
|
2025-08-27 16:19:54 +07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2025-09-18 08:01:49 +07:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
import '../../../../application/auth/check_phone_form/check_phone_form_bloc.dart';
|
2025-08-27 16:19:54 +07:00
|
|
|
import '../../../../common/theme/theme.dart';
|
2025-09-18 08:01:49 +07:00
|
|
|
import '../../../../domain/auth/auth.dart';
|
|
|
|
|
import '../../../../injection.dart';
|
2025-08-27 16:19:54 +07:00
|
|
|
import '../../../components/button/button.dart';
|
2025-09-18 08:01:49 +07:00
|
|
|
import '../../../components/toast/flushbar.dart';
|
2025-08-27 17:11:38 +07:00
|
|
|
import '../../../router/app_router.gr.dart';
|
2025-08-27 16:19:54 +07:00
|
|
|
import 'widgets/phone_field.dart';
|
|
|
|
|
|
|
|
|
|
@RoutePage()
|
2025-09-18 08:01:49 +07:00
|
|
|
class LoginPage extends StatelessWidget implements AutoRouteWrapper {
|
2025-08-27 16:19:54 +07:00
|
|
|
const LoginPage({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-09-18 08:01:49 +07:00
|
|
|
return BlocListener<CheckPhoneFormBloc, CheckPhoneFormState>(
|
|
|
|
|
listenWhen: (p, c) =>
|
|
|
|
|
p.failureOrCheckPhoneOption != c.failureOrCheckPhoneOption,
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
state.failureOrCheckPhoneOption.fold(
|
|
|
|
|
() => null,
|
|
|
|
|
(either) => either.fold(
|
|
|
|
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
|
|
|
|
(data) {
|
|
|
|
|
AppFlushbar.showSuccess(context, data.message);
|
|
|
|
|
Future.delayed(Duration(milliseconds: 1000), () {
|
|
|
|
|
log(data.toString());
|
|
|
|
|
if (data.status.isNotRegistered) {
|
|
|
|
|
context.router.push(RegisterRoute());
|
|
|
|
|
} else if (data.status.isPasswordRequired) {
|
|
|
|
|
context.router.push(
|
|
|
|
|
PasswordRoute(phoneNumber: data.phoneNumber),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(title: const Text('Masuk')),
|
|
|
|
|
body: BlocBuilder<CheckPhoneFormBloc, CheckPhoneFormState>(
|
|
|
|
|
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),
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
// Title
|
|
|
|
|
LoginPhoneField(),
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
const SizedBox(height: 50),
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
// Continue Button
|
|
|
|
|
AppElevatedButton(
|
|
|
|
|
onPressed: state.isSubmitting
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
context.read<CheckPhoneFormBloc>().add(
|
|
|
|
|
CheckPhoneFormEvent.submitted(),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
isLoading: state.isSubmitting,
|
|
|
|
|
title: 'Lanjutkan',
|
|
|
|
|
),
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
const SizedBox(height: 24),
|
2025-08-27 16:19:54 +07:00
|
|
|
|
2025-09-18 08:01:49 +07:00
|
|
|
// Terms and Conditions
|
|
|
|
|
Center(
|
|
|
|
|
child: RichText(
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
text: TextSpan(
|
|
|
|
|
style: AppStyle.md.copyWith(
|
|
|
|
|
color: AppColor.textSecondary,
|
|
|
|
|
height: 1.4,
|
|
|
|
|
),
|
|
|
|
|
children: [
|
|
|
|
|
const TextSpan(
|
|
|
|
|
text:
|
|
|
|
|
'Dengan masuk Enaklo, kamu telah\nmenyetujui ',
|
|
|
|
|
),
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: 'Syarat & Ketentuan',
|
|
|
|
|
style: AppStyle.md.copyWith(
|
|
|
|
|
color: AppColor.primary,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const TextSpan(text: ' dan\n'),
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: 'Kebijakan Privasi',
|
|
|
|
|
style: AppStyle.md.copyWith(
|
|
|
|
|
color: AppColor.primary,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-08-27 16:19:54 +07:00
|
|
|
),
|
|
|
|
|
),
|
2025-09-18 08:01:49 +07:00
|
|
|
|
|
|
|
|
const SizedBox(height: 40),
|
2025-08-27 16:19:54 +07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-09-18 08:01:49 +07:00
|
|
|
);
|
|
|
|
|
},
|
2025-08-27 16:19:54 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-09-18 08:01:49 +07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
|
|
|
|
create: (context) => getIt<CheckPhoneFormBloc>(),
|
|
|
|
|
child: this,
|
|
|
|
|
);
|
2025-08-27 16:19:54 +07:00
|
|
|
}
|