feat: sending otp and resend otp done
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:food_delivery_client/core/helpers/formatters.dart';
|
||||
import 'package:food_delivery_client/core/helpers/validator_helpers.dart';
|
||||
import 'package:food_delivery_client/feature/auth/domain/usecases/login_usecase.dart';
|
||||
import 'package:food_delivery_client/feature/auth/presentation/widgets/w_auth_background.dart';
|
||||
import '../../../../../../food_delivery_client.dart';
|
||||
import '../../../blocs/login_bloc/login_bloc.dart';
|
||||
@@ -110,7 +109,7 @@ class _WLoginBodyState extends State<WLoginBody> {
|
||||
alignment: AlignmentGeometry.centerRight,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
// context.push(Routes.verifyPhoneNumber, extra: false);
|
||||
context.push(Routes.verifyPhoneNumber, extra: false);
|
||||
},
|
||||
child: Text(
|
||||
context.loc.forgot_password,
|
||||
@@ -154,7 +153,7 @@ class _WLoginBodyState extends State<WLoginBody> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// context.push(Routes.verifyPhoneNumber, extra: true);
|
||||
context.push(Routes.verifyPhoneNumber, extra: true);
|
||||
},
|
||||
child: Text(
|
||||
context.loc.sign_up,
|
||||
|
||||
@@ -3,12 +3,12 @@ import 'package:food_delivery_client/feature/auth/presentation/pages/register_pa
|
||||
import '../../../../../food_delivery_client.dart';
|
||||
|
||||
class RegisterPage extends StatelessWidget {
|
||||
const RegisterPage({super.key});
|
||||
const RegisterPage({super.key, required this.phoneNumber});
|
||||
|
||||
final String phoneNumber;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WLayout(
|
||||
top: false,
|
||||
child: Scaffold(body: WRegisterBody()));
|
||||
return WLayout(top: false, child: Scaffold(body: WRegisterBody()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,10 @@ class _WRegisterBodyState extends State<WRegisterBody> {
|
||||
AppIcons.icArrowRightLight,
|
||||
).paddingOnly(left: 8),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState?.validate() ?? false) {}
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
),
|
||||
20.verticalSpace,
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'package:food_delivery_client/feature/auth/presentation/widgets/w_auth_ba
|
||||
import '../../../../../food_delivery_client.dart';
|
||||
|
||||
class ResetPasswordPage extends StatelessWidget {
|
||||
const ResetPasswordPage({super.key});
|
||||
|
||||
const ResetPasswordPage({super.key, required this.phoneNumber});
|
||||
final String phoneNumber;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WLayout(
|
||||
|
||||
@@ -1,17 +1,181 @@
|
||||
import 'package:food_delivery_client/core/helpers/time_formatters.dart';
|
||||
import 'package:food_delivery_client/feature/auth/domain/usecases/verify_otp_code_login_usecase.dart';
|
||||
import 'package:food_delivery_client/feature/auth/presentation/blocs/verify_otp_bloc/verify_otp_bloc.dart';
|
||||
import 'package:food_delivery_client/feature/auth/presentation/widgets/w_auth_background.dart';
|
||||
import 'package:pinput/pinput.dart';
|
||||
|
||||
import '../../../../../food_delivery_client.dart';
|
||||
|
||||
class VerifyOtpCodePage extends StatelessWidget {
|
||||
const VerifyOtpCodePage({super.key, required this.isRegister});
|
||||
class VerifyOtpCodePage extends StatefulWidget {
|
||||
const VerifyOtpCodePage({super.key, required this.params});
|
||||
|
||||
final bool isRegister;
|
||||
final OtpCodePageParams params;
|
||||
|
||||
@override
|
||||
State<VerifyOtpCodePage> createState() => _VerifyOtpCodePageState();
|
||||
}
|
||||
|
||||
class _VerifyOtpCodePageState extends State<VerifyOtpCodePage> {
|
||||
late TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller = TextEditingController();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final defaultPinTheme = PinTheme(
|
||||
height: 56,
|
||||
width: 56,
|
||||
textStyle: AppTextStyles.size18Medium,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppUtils.kBorderRadius8,
|
||||
border: Border.all(color: Color.fromRGBO(234, 239, 243, 1)),
|
||||
color: Color.fromRGBO(234, 234, 243, 1),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WLayout(
|
||||
top: false,
|
||||
child: Scaffold(body: WAuthBackground(child: Column())),
|
||||
return BlocProvider(
|
||||
create: (context) => sl<VerifyOtpBloc>()..add(VerifyOtpEvent.started()),
|
||||
child: BlocConsumer<VerifyOtpBloc, VerifyOtpState>(
|
||||
listener: (context, state) {
|
||||
if (state.status.isLoaded()) {
|
||||
if (widget.params.isRegister) {
|
||||
context.push(Routes.register, extra: widget.params.phoneNumber);
|
||||
} else {
|
||||
context.push(
|
||||
Routes.resetPassword,
|
||||
extra: widget.params.phoneNumber,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return WLayout(
|
||||
top: false,
|
||||
child: Scaffold(
|
||||
body: WAuthBackground(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
40.verticalSpace,
|
||||
Text(
|
||||
"Enter the 5-digit code sent to you at ${widget.params.phoneNumber}",
|
||||
style: AppTextStyles.size20Medium,
|
||||
),
|
||||
20.verticalSpace,
|
||||
Pinput(
|
||||
length: 5,
|
||||
enabled: true,
|
||||
controller: _controller,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
autofocus: true,
|
||||
showCursor: true,
|
||||
defaultPinTheme: defaultPinTheme,
|
||||
|
||||
focusedPinTheme: defaultPinTheme.copyWith(
|
||||
decoration: defaultPinTheme.decoration!.copyWith(
|
||||
color: Color.fromRGBO(234, 239, 243, 1),
|
||||
),
|
||||
),
|
||||
submittedPinTheme: defaultPinTheme.copyWith(
|
||||
decoration: defaultPinTheme.decoration!.copyWith(
|
||||
color: Color.fromRGBO(234, 239, 243, 1),
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
if (value.length == 5 && state.time > 0) {}
|
||||
},
|
||||
),
|
||||
10.verticalSpace,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("You can resend otp after"),
|
||||
|
||||
if (state.time != 0)
|
||||
Text(TimeFormatters.formatMinutesToTime(state.time)),
|
||||
|
||||
if (state.time == 0)
|
||||
state.resendStatus.isLoading()
|
||||
? CircularProgressIndicator.adaptive()
|
||||
: TextButton(
|
||||
onPressed: () {
|
||||
if (widget.params.isRegister) {
|
||||
context.read<VerifyOtpBloc>().add(
|
||||
VerifyOtpEvent.resendRegister(
|
||||
widget.params.phoneNumber,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<VerifyOtpBloc>().add(
|
||||
VerifyOtpEvent.resendForgot(
|
||||
widget.params.phoneNumber,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text("Resend"),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
20.verticalSpace,
|
||||
AppButton(
|
||||
name: context.loc.continue_str,
|
||||
onPressed: () {
|
||||
if (_controller.text.trim().length == 5 &&
|
||||
state.time > 0) {
|
||||
if (widget.params.isRegister) {
|
||||
context.read<VerifyOtpBloc>().add(
|
||||
VerifyOtpEvent.verifyOtpRegister(
|
||||
VerifyOtpCodeParams(
|
||||
phoneNumber: widget.params.phoneNumber,
|
||||
otpCode: _controller.text.trim().substring(
|
||||
0,
|
||||
4,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<VerifyOtpBloc>().add(
|
||||
VerifyOtpEvent.verifyOtpReset(
|
||||
VerifyOtpCodeParams(
|
||||
phoneNumber: widget.params.phoneNumber,
|
||||
otpCode: _controller.text.trim().substring(
|
||||
0,
|
||||
4,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
backgroundColor: AppColors.c34A853,
|
||||
borderRadius: 15,
|
||||
trailing: SvgPicture.asset(
|
||||
AppIcons.icArrowRightLight,
|
||||
).paddingOnly(left: 8),
|
||||
),
|
||||
],
|
||||
).paddingSymmetric(horizontal: 16),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:food_delivery_client/core/helpers/formatters.dart';
|
||||
import 'package:food_delivery_client/core/helpers/validator_helpers.dart';
|
||||
import 'package:food_delivery_client/feature/auth/domain/usecases/verify_otp_code_login_usecase.dart';
|
||||
import 'package:food_delivery_client/feature/auth/domain/usecases/verify_phone_login_usecase.dart';
|
||||
import 'package:food_delivery_client/feature/auth/presentation/blocs/verify_phone_bloc/verify_phone_bloc.dart';
|
||||
import 'package:food_delivery_client/feature/auth/presentation/widgets/w_auth_background.dart';
|
||||
|
||||
import '../../../../../food_delivery_client.dart';
|
||||
@@ -31,65 +34,106 @@ class _VerifyPhoneNumberPageState extends State<VerifyPhoneNumberPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: WLayout(
|
||||
top: false,
|
||||
child: Scaffold(
|
||||
body: WAuthBackground(
|
||||
child: SizedBox(
|
||||
width: context.w,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
50.verticalSpace,
|
||||
Text(
|
||||
context.loc.enter_phone_number,
|
||||
style: AppTextStyles.size20Medium,
|
||||
),
|
||||
20.verticalSpace,
|
||||
AppTextFormField(
|
||||
controller: _phoneNumberController,
|
||||
borderRadius: AppUtils.kBorderRadius8,
|
||||
hintText: context.loc.phone_number,
|
||||
keyBoardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
Formatters.phoneFormatter,
|
||||
LengthLimitingTextInputFormatter(12),
|
||||
],
|
||||
return BlocProvider(
|
||||
create: (context) => sl<VerifyPhoneBloc>(),
|
||||
child: BlocConsumer<VerifyPhoneBloc, VerifyPhoneState>(
|
||||
listener: (context, state) {
|
||||
if (state.status.isLoaded()) {
|
||||
context.push(
|
||||
Routes.verifyOtpCode,
|
||||
extra: OtpCodePageParams(
|
||||
phoneNumber:
|
||||
"+998${_phoneNumberController.text.trim().replaceAll(" ", "")}",
|
||||
isRegister: widget.isRegister,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: WLayout(
|
||||
top: false,
|
||||
child: Scaffold(
|
||||
body: WAuthBackground(
|
||||
child: SizedBox(
|
||||
width: context.w,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
50.verticalSpace,
|
||||
Text(
|
||||
context.loc.enter_phone_number,
|
||||
style: AppTextStyles.size20Medium,
|
||||
),
|
||||
20.verticalSpace,
|
||||
AppTextFormField(
|
||||
controller: _phoneNumberController,
|
||||
borderRadius: AppUtils.kBorderRadius8,
|
||||
hintText: context.loc.phone_number,
|
||||
keyBoardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
Formatters.phoneFormatter,
|
||||
LengthLimitingTextInputFormatter(12),
|
||||
],
|
||||
|
||||
prefixIcon: Text(
|
||||
"+ 998",
|
||||
style: AppTextStyles.size16Regular,
|
||||
),
|
||||
validator: (value) {
|
||||
return Validators.validatePhoneNumber(
|
||||
_phoneNumberController.text.trim(),
|
||||
);
|
||||
},
|
||||
prefixIcon: Text(
|
||||
"+ 998",
|
||||
style: AppTextStyles.size16Regular,
|
||||
),
|
||||
validator: (value) {
|
||||
return Validators.validatePhoneNumber(
|
||||
_phoneNumberController.text.trim(),
|
||||
);
|
||||
},
|
||||
),
|
||||
25.verticalSpace,
|
||||
AppButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
|
||||
|
||||
if (widget.isRegister) {
|
||||
context.read<VerifyPhoneBloc>().add(
|
||||
VerifyPhoneEvent.verifyPhoneRegister(
|
||||
VerifyPhoneNumberParams(
|
||||
phoneNumber:
|
||||
"+998${_phoneNumberController.text.trim().replaceAll(" ", "")}",
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<VerifyPhoneBloc>().add(
|
||||
VerifyPhoneEvent.verifyPhoneReset(
|
||||
VerifyPhoneNumberParams(
|
||||
phoneNumber:
|
||||
"+998${_phoneNumberController.text.trim().replaceAll(" ", "")}",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
name: context.loc.continue_str,
|
||||
borderRadius: 15,
|
||||
backgroundColor: AppColors.c34A853,
|
||||
),
|
||||
10.verticalSpace,
|
||||
Text(
|
||||
context.loc.consent_message("Felix Eats"),
|
||||
style: AppTextStyles.size12Medium.copyWith(
|
||||
color: AppColors.c888888,
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingSymmetric(horizontal: 16),
|
||||
),
|
||||
25.verticalSpace,
|
||||
AppButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState?.validate() ?? false) {}
|
||||
},
|
||||
name: context.loc.continue_str,
|
||||
borderRadius: 15,
|
||||
backgroundColor: AppColors.c34A853,
|
||||
),
|
||||
10.verticalSpace,
|
||||
Text(
|
||||
context.loc.consent_message("Felix Eats"),
|
||||
style: AppTextStyles.size12Medium.copyWith(
|
||||
color: AppColors.c888888,
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingSymmetric(horizontal: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user