@@ -8,9 +8,7 @@ import 'package:app_translations/app_translations.dart';
8
8
import 'package:app_ui/app_ui.dart' ;
9
9
import 'package:auto_route/auto_route.dart' ;
10
10
import 'package:flutter/material.dart' ;
11
- import 'package:flutter/services.dart' ;
12
11
import 'package:flutter_bloc/flutter_bloc.dart' ;
13
- import 'package:pinput/pinput.dart' ;
14
12
15
13
@RoutePage ()
16
14
class VerifyOTPScreen extends StatefulWidget implements AutoRouteWrapper {
@@ -42,88 +40,84 @@ class _VerifyOTPScreenState extends State<VerifyOTPScreen> with TickerProviderSt
42
40
automaticallyImplyLeading: true ,
43
41
title: context.t.verify_otp,
44
42
),
45
- body: SafeArea (
46
- child: BlocConsumer <VerifyOTPBloc , VerifyOTPState >(
47
- listener: (context, state) {
48
- if (state.verifyOtpStatus == ApiStatus .loaded && state.otp.value == '222222' ) {
49
- showAppSnackbar (context, 'OTP verified successfully!' );
50
- context.replaceRoute (const ChangePasswordRoute ());
51
- } else if (state.verifyOtpStatus == ApiStatus .error) {
52
- showAppSnackbar (context, 'Invalid OTP' , type: SnackbarType .failed);
53
- }
54
- },
55
- builder: (context, state) {
56
- return ListView (
57
- padding: const EdgeInsets .all (Insets .small12),
58
- children: [
59
- VSpace .large24 (),
60
- SlideAndFadeAnimationWrapper (delay: 100 , child: Center (child: Assets .images.logo.image (width: 100 ))),
61
- VSpace .large24 (),
62
- SlideAndFadeAnimationWrapper (
63
- delay: 200 ,
64
- child: Center (child: AppText .xsSemiBold (text: context.t.welcome, fontSize: 16 )),
43
+ body: BlocConsumer <VerifyOTPBloc , VerifyOTPState >(
44
+ listener: (context, state) {
45
+ if (state.verifyOtpStatus == ApiStatus .loaded && state.otp.value == '222222' ) {
46
+ showAppSnackbar (context, 'OTP verified successfully!' );
47
+ context.replaceRoute (const ChangePasswordRoute ());
48
+ } else if (state.verifyOtpStatus == ApiStatus .error) {
49
+ showAppSnackbar (context, 'Invalid OTP' , type: SnackbarType .failed);
50
+ }
51
+ },
52
+ builder: (context, state) {
53
+ return ListView (
54
+ padding: const EdgeInsets .all (Insets .small12),
55
+ children: [
56
+ VSpace .large24 (),
57
+ SlideAndFadeAnimationWrapper (delay: 100 , child: Center (child: Assets .images.logo.image (width: 100 ))),
58
+ VSpace .large24 (),
59
+ SlideAndFadeAnimationWrapper (
60
+ delay: 200 ,
61
+ child: Center (child: AppText .xsSemiBold (text: context.t.welcome, fontSize: 16 )),
62
+ ),
63
+ VSpace .large24 (),
64
+ AppTextField (initialValue: widget.emailAddress, label: context.t.email, isReadOnly: true ),
65
+ VSpace .medium16 (),
66
+ Center (
67
+ child: Padding (
68
+ padding: const EdgeInsets .all (Insets .small12),
69
+ child: AppText .sSemiBold (text: context.t.enter_otp),
65
70
),
66
- VSpace .large24 (),
67
- AppTextField (initialValue: widget.emailAddress, label: context.t.email, isReadOnly: true ),
68
- VSpace .medium16 (),
71
+ ),
72
+ VSpace .small12 (),
73
+ AppOtpInput (
74
+ errorText: state.otp.error != null ? context.t.pin_incorrect : null ,
75
+ onChanged: (value) {
76
+ context.read <VerifyOTPBloc >().add (VerifyOTPChanged (value));
77
+ },
78
+ ),
79
+
80
+ VSpace .xsmall8 (),
81
+ if (state.isTimerRunning)
69
82
Center (
70
- child: Padding (
71
- padding: const EdgeInsets .all (Insets .small12),
72
- child: AppText .sSemiBold (text: context.t.enter_otp),
83
+ child: AppTimer (
84
+ seconds: 30 ,
85
+ onFinished: () {
86
+ context.read <VerifyOTPBloc >().add (const TimerFinishedEvent ());
87
+ },
73
88
),
74
89
),
75
- VSpace .small12 (),
76
- Pinput (
77
- length: 6 ,
78
- separatorBuilder: (index) => HSpace .xxsmall4 (),
79
- errorText: state.otp.error != null ? context.t.pin_incorrect : null ,
80
- onChanged: (value) {
81
- context.read <VerifyOTPBloc >().add (VerifyOTPChanged (value));
82
- },
83
- inputFormatters: [FilteringTextInputFormatter .digitsOnly],
84
- ),
85
- VSpace .xsmall8 (),
86
- if (state.isTimerRunning)
87
- Center (
88
- child: AppTimer (
89
- seconds: 30 ,
90
- onFinished: () {
91
- context.read <VerifyOTPBloc >().add (const TimerFinishedEvent ());
92
- },
93
- ),
90
+ VSpace .small12 (),
91
+ Row (
92
+ mainAxisAlignment: MainAxisAlignment .center,
93
+ children: [
94
+ AppText .xsRegular (color: context.colorScheme.black, text: context.t.did_not_receive_otp),
95
+ AppButton (
96
+ text: context.t.resend_otp,
97
+ buttonType: ButtonType .text,
98
+ textColor: context.colorScheme.primary400,
99
+ onPressed:
100
+ state.isTimerRunning
101
+ ? null
102
+ : () {
103
+ FocusScope .of (context).unfocus ();
104
+ context.read <VerifyOTPBloc >().add (const ResendEmailEvent ());
105
+ },
94
106
),
95
- VSpace .small12 (),
96
- Row (
97
- mainAxisAlignment: MainAxisAlignment .center,
98
- children: [
99
- AppText .xsRegular (color: context.colorScheme.black, text: context.t.did_not_receive_otp),
100
- AppButton (
101
- text: context.t.resend_otp,
102
- buttonType: ButtonType .text,
103
- textColor: context.colorScheme.primary400,
104
- onPressed:
105
- state.isTimerRunning
106
- ? null
107
- : () {
108
- FocusScope .of (context).unfocus ();
109
- context.read <VerifyOTPBloc >().add (const ResendEmailEvent ());
110
- },
111
- ),
112
- HSpace .xsmall8 (),
113
- ],
114
- ),
115
- VSpace .large24 (),
116
- AppButton (
117
- isExpanded: true ,
118
- padding: const EdgeInsets .symmetric (horizontal: Insets .large24),
119
- text: context.t.verify_otp,
120
- isLoading: state.verifyOtpStatus == ApiStatus .loading,
121
- onPressed: () => context.read <VerifyOTPBloc >().add (const VerifyButtonPressed ()),
122
- ),
123
- ],
124
- );
125
- },
126
- ),
107
+ HSpace .xsmall8 (),
108
+ ],
109
+ ),
110
+ VSpace .large24 (),
111
+ AppButton (
112
+ isExpanded: true ,
113
+ padding: const EdgeInsets .symmetric (horizontal: Insets .large24),
114
+ text: context.t.verify_otp,
115
+ isLoading: state.verifyOtpStatus == ApiStatus .loading,
116
+ onPressed: () => context.read <VerifyOTPBloc >().add (const VerifyButtonPressed ()),
117
+ ),
118
+ ],
119
+ );
120
+ },
127
121
),
128
122
);
129
123
}
0 commit comments