check phone impl

This commit is contained in:
efrilm
2025-09-18 08:01:49 +07:00
parent 214dfe3262
commit 1ca1a45126
15 changed files with 275 additions and 80 deletions
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../../../common/theme/theme.dart';
@@ -7,12 +7,14 @@ class AppElevatedButton extends StatelessWidget {
required this.title,
this.width = double.infinity,
this.height = 48.0,
this.isLoading = false,
});
final Function()? onPressed;
final String title;
final double width;
final double height;
final bool isLoading;
@override
Widget build(BuildContext context) {
@@ -21,13 +23,29 @@ class AppElevatedButton extends StatelessWidget {
height: height,
child: ElevatedButton(
onPressed: onPressed,
child: Text(
title,
style: AppStyle.lg.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w700,
),
),
child: isLoading
? Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SpinKitFadingCircle(color: AppColor.white, size: 24),
SizedBox(width: 8),
Text(
'Loading',
style: AppStyle.lg.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w700,
),
),
],
)
: Text(
title,
style: AppStyle.lg.copyWith(
color: AppColor.white,
fontWeight: FontWeight.w700,
),
),
),
);
}
@@ -11,6 +11,7 @@ class AppTextFormField extends StatelessWidget {
this.suffixIcon,
this.keyboardType,
this.onChanged,
this.validator,
});
final String? hintText;
@@ -21,6 +22,7 @@ class AppTextFormField extends StatelessWidget {
final Widget? suffixIcon;
final TextInputType? keyboardType;
final ValueChanged<String>? onChanged;
final String? Function(String?)? validator;
@override
Widget build(BuildContext context) {
@@ -39,6 +41,7 @@ class AppTextFormField extends StatelessWidget {
color: AppColor.textPrimary,
fontWeight: FontWeight.w500,
),
validator: validator,
decoration: InputDecoration(
hintText: hintText,
prefixIcon: prefixIcon,
@@ -0,0 +1,54 @@
import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import '../../../common/theme/theme.dart';
import '../../../domain/auth/auth.dart';
class AppFlushbar {
static void showSuccess(BuildContext context, String message) {
Flushbar(
messageText: Text(
message,
style: AppStyle.lg.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
icon: const Icon(Icons.check_circle, color: Colors.white),
duration: const Duration(seconds: 2),
flushbarPosition: FlushbarPosition.BOTTOM,
backgroundColor: AppColor.secondary,
borderRadius: BorderRadius.circular(12),
margin: const EdgeInsets.all(12),
).show(context);
}
static void showError(BuildContext context, String message) {
Flushbar(
messageText: Text(
message,
style: AppStyle.lg.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
icon: const Icon(Icons.error, color: Colors.white),
duration: const Duration(seconds: 3),
flushbarPosition: FlushbarPosition.BOTTOM,
backgroundColor: AppColor.error,
borderRadius: BorderRadius.circular(12),
margin: const EdgeInsets.all(12),
).show(context);
}
static void showAuthFailureToast(BuildContext context, AuthFailure failure) =>
showError(
context,
failure.map(
serverError: (value) => value.failure.toStringFormatted(context),
dynamicErrorMessage: (value) => value.erroMessage,
unexpectedError: (value) => 'Terjadi kesalahan, silahkan coba lagi',
),
);
}
+106 -53
View File
@@ -1,78 +1,131 @@
import 'dart:developer';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../application/auth/check_phone_form/check_phone_form_bloc.dart';
import '../../../../common/theme/theme.dart';
import '../../../../domain/auth/auth.dart';
import '../../../../injection.dart';
import '../../../components/button/button.dart';
import '../../../components/toast/flushbar.dart';
import '../../../router/app_router.gr.dart';
import 'widgets/phone_field.dart';
@RoutePage()
class LoginPage extends StatelessWidget {
class LoginPage extends StatelessWidget implements AutoRouteWrapper {
const LoginPage({super.key});
@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),
// Title
LoginPhoneField(),
const SizedBox(height: 50),
// Continue Button
AppElevatedButton(
onPressed: () {
context.router.push(RegisterRoute());
},
title: 'Lanjutkan',
),
const SizedBox(height: 24),
// Terms and Conditions
Center(
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: AppStyle.md.copyWith(
color: AppColor.textSecondary,
height: 1.4,
),
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 TextSpan(
text: 'Dengan masuk Enaklo, kamu telah\nmenyetujui ',
const SizedBox(height: 40),
// Title
LoginPhoneField(),
const SizedBox(height: 50),
// Continue Button
AppElevatedButton(
onPressed: state.isSubmitting
? null
: () {
context.read<CheckPhoneFormBloc>().add(
CheckPhoneFormEvent.submitted(),
);
},
isLoading: state.isSubmitting,
title: 'Lanjutkan',
),
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,
const SizedBox(height: 24),
// 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,
),
),
],
),
),
),
const SizedBox(height: 40),
],
),
),
),
const SizedBox(height: 40),
],
);
},
),
),
);
}
@override
Widget wrappedRoute(BuildContext context) => BlocProvider(
create: (context) => getIt<CheckPhoneFormBloc>(),
child: this,
);
}
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../../application/auth/check_phone_form/check_phone_form_bloc.dart';
import '../../../../../common/theme/theme.dart';
import '../../../../components/field/field.dart';
@@ -45,6 +47,13 @@ class _LoginPhoneFieldState extends State<LoginPhoneField> {
controller: _controller,
focusNode: _focusNode,
keyboardType: TextInputType.phone,
validator: (value) {
if (context.read<CheckPhoneFormBloc>().state.phoneNumber.isEmpty) {
return 'Masukkan no telepon';
}
return null;
},
prefixIcon: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
@@ -64,7 +73,9 @@ class _LoginPhoneFieldState extends State<LoginPhoneField> {
)
: null,
onChanged: (value) {
setState(() {});
context.read<CheckPhoneFormBloc>().add(
CheckPhoneFormEvent.phoneNumberChanged(value),
);
},
);
}
@@ -7,12 +7,13 @@ import '../../../router/app_router.gr.dart';
@RoutePage()
class PasswordPage extends StatelessWidget {
const PasswordPage({super.key});
final String phoneNumber;
const PasswordPage({super.key, required this.phoneNumber});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Buat Kata Sandi')),
appBar: AppBar(title: const Text('Kata Sandi')),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
+26 -5
View File
@@ -255,7 +255,7 @@ class LoginRoute extends _i33.PageRouteInfo<void> {
static _i33.PageInfo page = _i33.PageInfo(
name,
builder: (data) {
return const _i12.LoginPage();
return _i33.WrappedRoute(child: const _i12.LoginPage());
},
);
}
@@ -432,20 +432,41 @@ class OtpRoute extends _i33.PageRouteInfo<void> {
/// generated route for
/// [_i21.PasswordPage]
class PasswordRoute extends _i33.PageRouteInfo<void> {
const PasswordRoute({List<_i33.PageRouteInfo>? children})
: super(PasswordRoute.name, initialChildren: children);
class PasswordRoute extends _i33.PageRouteInfo<PasswordRouteArgs> {
PasswordRoute({
_i34.Key? key,
required String phoneNumber,
List<_i33.PageRouteInfo>? children,
}) : super(
PasswordRoute.name,
args: PasswordRouteArgs(key: key, phoneNumber: phoneNumber),
initialChildren: children,
);
static const String name = 'PasswordRoute';
static _i33.PageInfo page = _i33.PageInfo(
name,
builder: (data) {
return const _i21.PasswordPage();
final args = data.argsAs<PasswordRouteArgs>();
return _i21.PasswordPage(key: args.key, phoneNumber: args.phoneNumber);
},
);
}
class PasswordRouteArgs {
const PasswordRouteArgs({this.key, required this.phoneNumber});
final _i34.Key? key;
final String phoneNumber;
@override
String toString() {
return 'PasswordRouteArgs{key: $key, phoneNumber: $phoneNumber}';
}
}
/// generated route for
/// [_i22.PaymentPage]
class PaymentRoute extends _i33.PageRouteInfo<void> {