Otp Page
This commit is contained in:
parent
0ea1a6fa56
commit
8e35582f93
@ -4,5 +4,5 @@ class ApiPath {
|
|||||||
static String verify = '/api/v1/customer-auth/register/verify-otp';
|
static String verify = '/api/v1/customer-auth/register/verify-otp';
|
||||||
static String setPassword = '/api/v1/customer-auth/register/set-password';
|
static String setPassword = '/api/v1/customer-auth/register/set-password';
|
||||||
static String login = '/api/v1/customer-auth/login';
|
static String login = '/api/v1/customer-auth/login';
|
||||||
static String resend = '/api/v1/customer-auth/register/resend-otp';
|
static String resend = '/api/v1/customer-auth/resend-otp';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,17 +2,45 @@ import 'dart:async';
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
import '../../../../application/auth/resend_form/resend_form_bloc.dart';
|
||||||
|
import '../../../../application/auth/verify_form/verify_form_bloc.dart';
|
||||||
import '../../../../common/theme/theme.dart';
|
import '../../../../common/theme/theme.dart';
|
||||||
|
import '../../../../domain/auth/auth.dart';
|
||||||
|
import '../../../../injection.dart';
|
||||||
|
import '../../../components/toast/flushbar.dart';
|
||||||
import '../../../router/app_router.gr.dart';
|
import '../../../router/app_router.gr.dart';
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class OtpPage extends StatefulWidget {
|
class OtpPage extends StatefulWidget implements AutoRouteWrapper {
|
||||||
final String registrationToken;
|
final String registrationToken;
|
||||||
const OtpPage({super.key, required this.registrationToken});
|
final String phoneNumber;
|
||||||
|
|
||||||
|
const OtpPage({
|
||||||
|
super.key,
|
||||||
|
required this.registrationToken,
|
||||||
|
required this.phoneNumber,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<OtpPage> createState() => _OtpPageState();
|
State<OtpPage> createState() => _OtpPageState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget wrappedRoute(BuildContext context) => MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => getIt<VerifyFormBloc>()
|
||||||
|
..add(VerifyFormEvent.registrationTokenChanged(registrationToken)),
|
||||||
|
),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => getIt<ResendFormBloc>()
|
||||||
|
..add(ResendFormEvent.phoneNumberChanged(phoneNumber))
|
||||||
|
..add(ResendFormEvent.purposeChanged('registration')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: this,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _OtpPageState extends State<OtpPage> {
|
class _OtpPageState extends State<OtpPage> {
|
||||||
@ -54,6 +82,7 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
});
|
});
|
||||||
_startTimer();
|
_startTimer();
|
||||||
// Add your resend logic here
|
// Add your resend logic here
|
||||||
|
context.read<ResendFormBloc>().add(ResendFormEvent.submitted());
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatTime(int seconds) {
|
String _formatTime(int seconds) {
|
||||||
@ -83,7 +112,9 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
void _verifyCode() {
|
void _verifyCode() {
|
||||||
String code = _controllers.map((controller) => controller.text).join();
|
String code = _controllers.map((controller) => controller.text).join();
|
||||||
if (code.length == 6) {
|
if (code.length == 6) {
|
||||||
context.router.push(CreatePasswordRoute());
|
// context.router.push(CreatePasswordRoute());
|
||||||
|
context.read<VerifyFormBloc>().add(VerifyFormEvent.otpCodeChanged(code));
|
||||||
|
context.read<VerifyFormBloc>().add(VerifyFormEvent.submitted());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +132,47 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return MultiBlocListener(
|
||||||
|
listeners: [
|
||||||
|
BlocListener<VerifyFormBloc, VerifyFormState>(
|
||||||
|
listenWhen: (p, c) =>
|
||||||
|
p.failureOrVerifyOption != c.failureOrVerifyOption,
|
||||||
|
listener: (context, state) {
|
||||||
|
state.failureOrVerifyOption.fold(
|
||||||
|
() {},
|
||||||
|
(either) => either.fold(
|
||||||
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||||
|
(data) {
|
||||||
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
|
Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
|
context.router.push(CreatePasswordRoute());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
BlocListener<ResendFormBloc, ResendFormState>(
|
||||||
|
listenWhen: (p, c) =>
|
||||||
|
p.failureOrResendOption != c.failureOrResendOption,
|
||||||
|
listener: (context, state) {
|
||||||
|
state.failureOrResendOption.fold(
|
||||||
|
() {},
|
||||||
|
(either) => either.fold(
|
||||||
|
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||||
|
(data) {
|
||||||
|
if (data.status.isSuccess) {
|
||||||
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
|
} else {
|
||||||
|
AppFlushbar.showError(context, data.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: Scaffold(
|
||||||
appBar: AppBar(title: Text('Verifikasi')),
|
appBar: AppBar(title: Text('Verifikasi')),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||||
@ -148,7 +219,7 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: '+6288976680234',
|
text: '+${widget.phoneNumber}',
|
||||||
style: AppStyle.sm.copyWith(
|
style: AppStyle.sm.copyWith(
|
||||||
color: AppColor.textPrimary,
|
color: AppColor.textPrimary,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
@ -173,7 +244,9 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
focusNode: _focusNodes[index],
|
focusNode: _focusNodes[index],
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
maxLength: 1,
|
maxLength: 1,
|
||||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.digitsOnly,
|
||||||
|
],
|
||||||
decoration: InputDecoration(counterText: ''),
|
decoration: InputDecoration(counterText: ''),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: AppStyle.lg.copyWith(
|
style: AppStyle.lg.copyWith(
|
||||||
@ -232,6 +305,7 @@ class _OtpPageState extends State<OtpPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,10 @@ class RegisterPage extends StatelessWidget implements AutoRouteWrapper {
|
|||||||
AppFlushbar.showSuccess(context, data.message);
|
AppFlushbar.showSuccess(context, data.message);
|
||||||
Future.delayed(Duration(milliseconds: 1000), () {
|
Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
context.router.push(
|
context.router.push(
|
||||||
OtpRoute(registrationToken: data.registrationToken),
|
OtpRoute(
|
||||||
|
registrationToken: data.registrationToken,
|
||||||
|
phoneNumber: phoneNumber,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@ -420,10 +420,15 @@ class OtpRoute extends _i33.PageRouteInfo<OtpRouteArgs> {
|
|||||||
OtpRoute({
|
OtpRoute({
|
||||||
_i34.Key? key,
|
_i34.Key? key,
|
||||||
required String registrationToken,
|
required String registrationToken,
|
||||||
|
required String phoneNumber,
|
||||||
List<_i33.PageRouteInfo>? children,
|
List<_i33.PageRouteInfo>? children,
|
||||||
}) : super(
|
}) : super(
|
||||||
OtpRoute.name,
|
OtpRoute.name,
|
||||||
args: OtpRouteArgs(key: key, registrationToken: registrationToken),
|
args: OtpRouteArgs(
|
||||||
|
key: key,
|
||||||
|
registrationToken: registrationToken,
|
||||||
|
phoneNumber: phoneNumber,
|
||||||
|
),
|
||||||
initialChildren: children,
|
initialChildren: children,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -433,24 +438,33 @@ class OtpRoute extends _i33.PageRouteInfo<OtpRouteArgs> {
|
|||||||
name,
|
name,
|
||||||
builder: (data) {
|
builder: (data) {
|
||||||
final args = data.argsAs<OtpRouteArgs>();
|
final args = data.argsAs<OtpRouteArgs>();
|
||||||
return _i20.OtpPage(
|
return _i33.WrappedRoute(
|
||||||
|
child: _i20.OtpPage(
|
||||||
key: args.key,
|
key: args.key,
|
||||||
registrationToken: args.registrationToken,
|
registrationToken: args.registrationToken,
|
||||||
|
phoneNumber: args.phoneNumber,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class OtpRouteArgs {
|
class OtpRouteArgs {
|
||||||
const OtpRouteArgs({this.key, required this.registrationToken});
|
const OtpRouteArgs({
|
||||||
|
this.key,
|
||||||
|
required this.registrationToken,
|
||||||
|
required this.phoneNumber,
|
||||||
|
});
|
||||||
|
|
||||||
final _i34.Key? key;
|
final _i34.Key? key;
|
||||||
|
|
||||||
final String registrationToken;
|
final String registrationToken;
|
||||||
|
|
||||||
|
final String phoneNumber;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'OtpRouteArgs{key: $key, registrationToken: $registrationToken}';
|
return 'OtpRouteArgs{key: $key, registrationToken: $registrationToken, phoneNumber: $phoneNumber}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user