mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
Added dialogue for success message
This commit is contained in:
@ -232,13 +232,15 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reSendOtp() async {
|
Future<bool> reSendOtp() async {
|
||||||
try {
|
try {
|
||||||
emit(AuthLoading());
|
emit(AuthLoading());
|
||||||
await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'VERIFICATION'});
|
await AuthenticationAPI.sendOtp(body: {'email': email, 'type': 'VERIFICATION'});
|
||||||
emit(ResendOtpSuccess());
|
emit(ResendOtpSuccess());
|
||||||
|
return true;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
emit(AuthLoginError(message: 'Something went wrong'));
|
emit(AuthLoginError(message: 'Something went wrong'));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import 'package:pin_code_fields/pin_code_fields.dart';
|
|||||||
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/create_new_password.dart';
|
import 'package:syncrow_app/features/auth/view/create_new_password.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/success_dialog.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||||
import 'package:syncrow_app/generated/assets.dart';
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
@ -40,13 +41,19 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
_lifecycleEventHandler = LifecycleEventHandler(
|
_lifecycleEventHandler = LifecycleEventHandler(
|
||||||
resumeCallBack: () async {
|
resumeCallBack: () async {
|
||||||
SharedPreferencesHelper.saveBoolToSP('timeStampSaved', false);
|
SharedPreferencesHelper.saveBoolToSP('timeStampSaved', false);
|
||||||
String timeStampInBackground = await SharedPreferencesHelper.readStringFromSP('timeStamp');
|
String timeStampInBackground =
|
||||||
int savedCounter = await SharedPreferencesHelper.readIntFromSP('savedCounter');
|
await SharedPreferencesHelper.readStringFromSP('timeStamp');
|
||||||
|
int savedCounter =
|
||||||
|
await SharedPreferencesHelper.readIntFromSP('savedCounter');
|
||||||
DateTime currentTime = DateTime.now();
|
DateTime currentTime = DateTime.now();
|
||||||
int differenceInSeconds = timeStampInBackground.isNotEmpty
|
int differenceInSeconds = timeStampInBackground.isNotEmpty
|
||||||
? currentTime.difference(DateTime.parse(timeStampInBackground)).inSeconds
|
? currentTime
|
||||||
|
.difference(DateTime.parse(timeStampInBackground))
|
||||||
|
.inSeconds
|
||||||
: 0;
|
: 0;
|
||||||
remainingSec = differenceInSeconds > savedCounter ? 0 : savedCounter - differenceInSeconds;
|
remainingSec = differenceInSeconds > savedCounter
|
||||||
|
? 0
|
||||||
|
: savedCounter - differenceInSeconds;
|
||||||
timerStarted = true;
|
timerStarted = true;
|
||||||
startTimer(remainingSec ?? 0);
|
startTimer(remainingSec ?? 0);
|
||||||
return;
|
return;
|
||||||
@ -75,7 +82,8 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTimerOnBackground() async {
|
handleTimerOnBackground() async {
|
||||||
bool timeStampSaved = await SharedPreferencesHelper.readBoolFromSP('timeStampSaved') ?? false;
|
bool timeStampSaved =
|
||||||
|
await SharedPreferencesHelper.readBoolFromSP('timeStampSaved') ?? false;
|
||||||
if (!timeStampSaved) {
|
if (!timeStampSaved) {
|
||||||
final dateInString = DateTime.now().toString();
|
final dateInString = DateTime.now().toString();
|
||||||
SharedPreferencesHelper.saveIntToSP('savedCounter', remainingSec ?? 0);
|
SharedPreferencesHelper.saveIntToSP('savedCounter', remainingSec ?? 0);
|
||||||
@ -115,7 +123,8 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String maskedEmail = AuthCubit.get(context).maskEmail(AuthCubit.get(context).email);
|
String maskedEmail =
|
||||||
|
AuthCubit.get(context).maskEmail(AuthCubit.get(context).email);
|
||||||
return BlocConsumer<AuthCubit, AuthState>(
|
return BlocConsumer<AuthCubit, AuthState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is AuthOtpSuccess) {
|
if (state is AuthOtpSuccess) {
|
||||||
@ -199,7 +208,10 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
child: RichText(
|
child: RichText(
|
||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
text: 'We have sent the verification code to',
|
text: 'We have sent the verification code to',
|
||||||
style: Theme.of(context).textTheme.titleSmall!.copyWith(
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleSmall!
|
||||||
|
.copyWith(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontWeight: FontsManager.regular,
|
fontWeight: FontsManager.regular,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
@ -207,7 +219,10 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: ' $maskedEmail',
|
text: ' $maskedEmail',
|
||||||
style: Theme.of(context).textTheme.titleSmall!.copyWith(
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleSmall!
|
||||||
|
.copyWith(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontWeight: FontsManager.bold,
|
fontWeight: FontsManager.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
@ -215,7 +230,10 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: ' change email?',
|
text: ' change email?',
|
||||||
style: Theme.of(context).textTheme.titleSmall!.copyWith(
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleSmall!
|
||||||
|
.copyWith(
|
||||||
color: const Color(0xFF87C7FF),
|
color: const Color(0xFF87C7FF),
|
||||||
fontWeight: FontsManager.regular,
|
fontWeight: FontsManager.regular,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
@ -239,7 +257,8 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
autoFocus: true,
|
autoFocus: true,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
animationDuration: const Duration(milliseconds: 30),
|
animationDuration:
|
||||||
|
const Duration(milliseconds: 30),
|
||||||
beforeTextPaste: (text) {
|
beforeTextPaste: (text) {
|
||||||
// Allow pasting only if all characters are numeric
|
// Allow pasting only if all characters are numeric
|
||||||
return int.tryParse(text!) != null;
|
return int.tryParse(text!) != null;
|
||||||
@ -262,18 +281,27 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
errorBorderWidth: 1,
|
errorBorderWidth: 1,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
errorBorderColor: Colors.red,
|
errorBorderColor: Colors.red,
|
||||||
activeColor: state is AuthLoginError ? Colors.red : Colors.white,
|
activeColor: state is AuthLoginError
|
||||||
inactiveColor:
|
? Colors.red
|
||||||
state is AuthLoginError ? Colors.red : Colors.white,
|
: Colors.white,
|
||||||
activeFillColor:
|
inactiveColor: state is AuthLoginError
|
||||||
state is AuthLoginError ? Colors.red : Colors.white,
|
? Colors.red
|
||||||
inactiveFillColor:
|
: Colors.white,
|
||||||
state is AuthLoginError ? Colors.red : Colors.white,
|
activeFillColor: state is AuthLoginError
|
||||||
selectedFillColor:
|
? Colors.red
|
||||||
state is AuthLoginError ? Colors.red : Colors.white,
|
: Colors.white,
|
||||||
|
inactiveFillColor: state is AuthLoginError
|
||||||
|
? Colors.red
|
||||||
|
: Colors.white,
|
||||||
|
selectedFillColor: state is AuthLoginError
|
||||||
|
? Colors.red
|
||||||
|
: Colors.white,
|
||||||
disabledColor: Colors.white,
|
disabledColor: Colors.white,
|
||||||
fieldHeight: 56,
|
fieldHeight: 56,
|
||||||
fieldWidth: MediaQuery.sizeOf(context).width > 340 ? 40 : 20,
|
fieldWidth:
|
||||||
|
MediaQuery.sizeOf(context).width > 340
|
||||||
|
? 40
|
||||||
|
: 20,
|
||||||
// fieldWidth: 40,
|
// fieldWidth: 40,
|
||||||
selectedColor: Colors.white,
|
selectedColor: Colors.white,
|
||||||
shape: PinCodeFieldShape.box,
|
shape: PinCodeFieldShape.box,
|
||||||
@ -295,10 +323,12 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
isDone: state is AuthLoginSuccess,
|
isDone: state is AuthLoginSuccess,
|
||||||
isLoading: state is AuthLoading,
|
isLoading: state is AuthLoading,
|
||||||
customButtonStyle: ButtonStyle(
|
customButtonStyle: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(
|
backgroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.black.withOpacity(.25),
|
Colors.black.withOpacity(.25),
|
||||||
),
|
),
|
||||||
foregroundColor: MaterialStateProperty.all(
|
foregroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.white,
|
Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -307,7 +337,8 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if ((state is! AuthLoading)) {
|
if ((state is! AuthLoading)) {
|
||||||
AuthCubit.get(context).verifyOtp(widget.isForgetPage);
|
AuthCubit.get(context)
|
||||||
|
.verifyOtp(widget.isForgetPage);
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -321,10 +352,12 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
isDone: state is AuthLoginSuccess,
|
isDone: state is AuthLoginSuccess,
|
||||||
isLoading: state is AuthLoading,
|
isLoading: state is AuthLoading,
|
||||||
customButtonStyle: ButtonStyle(
|
customButtonStyle: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(
|
backgroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.black.withOpacity(.25),
|
Colors.black.withOpacity(.25),
|
||||||
),
|
),
|
||||||
foregroundColor: MaterialStateProperty.all(
|
foregroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.white,
|
Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -341,8 +374,20 @@ class _OtpViewState extends State<OtpView> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((state is! AuthLoading)) {
|
if ((state is! AuthLoading)) {
|
||||||
await AuthCubit.get(context).reSendOtp();
|
bool success = await AuthCubit.get(context)
|
||||||
|
.reSendOtp();
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
|
if(success){
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => SuccessDialog(
|
||||||
|
key: ValueKey('SuccessDialog'),
|
||||||
|
message: 'New OTP sent!',));
|
||||||
|
}
|
||||||
|
Future.delayed(Duration(seconds: 2),
|
||||||
|
() {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user