Exception Widget & Fixes

merge-update-with-lab-changes
Aamir Muhammad 7 months ago committed by haroon amjad
parent 8c8665a2f0
commit a7e310226e

@ -2362,6 +2362,7 @@ const Map localizedValues = {
"enterPhoneDesc": {"en": "Enter your phone number to receive OTP verification code", "ar":"أدخل رقم هاتفك لتلقي رمز التحقق OTP"}, "enterPhoneDesc": {"en": "Enter your phone number to receive OTP verification code", "ar":"أدخل رقم هاتفك لتلقي رمز التحقق OTP"},
"otpVerification": {"en": "OTP Verification", "ar":"التحقق من OTP"}, "otpVerification": {"en": "OTP Verification", "ar":"التحقق من OTP"},
"submiT": {"en": "Submit", "ar":"إرسال"}, "submiT": {"en": "Submit", "ar":"إرسال"},
"notice": {"en": "Notice", "ar":"إشعار"},

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
@ -32,6 +34,7 @@ class _ExceptionBottomSheetState extends State<ExceptionBottomSheet> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SafeArea( return SafeArea(
bottom: Platform.isIOS ? false : true, // Adjust for iOS to avoid bottom padding
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
FocusScope.of(context).unfocus(); // Dismiss the keyboard when tapping outside FocusScope.of(context).unfocus(); // Dismiss the keyboard when tapping outside
@ -53,7 +56,7 @@ class _ExceptionBottomSheetState extends State<ExceptionBottomSheet> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
AppText("Error", fontSize: 28, letterSpacing: -2, color: Color(0xFF2E3039), fontWeight: FontWeight.w600), AppText(TranslationBase.of(context).notice, fontSize: 28, letterSpacing: -2, color: Color(0xFF2E3039), fontWeight: FontWeight.w600),
InkWell( InkWell(
onTap: () { onTap: () {
Navigator.of(context).pop(); Navigator.of(context).pop();

@ -717,7 +717,7 @@ class _RegisterNew extends State<RegisterNew> {
}); });
} else { } else {
if (value['IsAuthenticated']) { if (value['IsAuthenticated']) {
checkActivationCode(); checkActivationCode(onWrongActivationCode: (String? message, bool? isReroute) {});
} }
} }
}).catchError((err) { }).catchError((err) {
@ -757,7 +757,7 @@ class _RegisterNew extends State<RegisterNew> {
} }
} }
Future<void> checkActivationCode({value, type, skipRegistration}) async { Future<void> checkActivationCode({value, type, skipRegistration, required Function(String? message, bool? isReroute) onWrongActivationCode}) async {
final isSaudi = selectedCountry.countryCode == "966"; final isSaudi = selectedCountry.countryCode == "966";
final isHijriDate = isHijri == 1; final isHijriDate = isHijri == 1;
final dobString = isHijriDate ? selectedDOB!.toString() : dateFormat.format(selectedDOB!); final dobString = isHijriDate ? selectedDOB!.toString() : dateFormat.format(selectedDOB!);
@ -802,15 +802,7 @@ class _RegisterNew extends State<RegisterNew> {
final activation = CheckActivationCode.fromJson(result as Map<String, dynamic>); final activation = CheckActivationCode.fromJson(result as Map<String, dynamic>);
if (activation.errorCode == '699') { if (activation.errorCode == '699') {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(activation.errorEndUserMessage.toString(), true);
child: ExceptionBottomSheet(
message: activation.errorEndUserMessage,
showCancel: false,
onOkPressed: () {
Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin));
},
),
);
} else { } else {
await sharedPref.remove(FAMILY_FILE); await sharedPref.remove(FAMILY_FILE);
activation.list!.isFamily = false; activation.list!.isFamily = false;
@ -829,15 +821,16 @@ class _RegisterNew extends State<RegisterNew> {
} }
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(result.toString(), false);
child: ExceptionBottomSheet( // context.showBottomSheet(
message: result, // child: ExceptionBottomSheet(
showCancel: false, // message: result,
onOkPressed: () { // showCancel: false,
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
projectViewModel.analytics.loginRegistration.login_fail(error: result); projectViewModel.analytics.loginRegistration.login_fail(error: result);
projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result);
} }
@ -851,29 +844,31 @@ class _RegisterNew extends State<RegisterNew> {
// Optionally: Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); // Optionally: Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew));
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(result.toString(), false);
child: ExceptionBottomSheet( // context.showBottomSheet(
message: result, // child: ExceptionBottomSheet(
showCancel: false, // message: result,
onOkPressed: () { // showCancel: false,
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
// Optionally: log analytics here // Optionally: log analytics here
} }
} }
} catch (err) { } catch (err) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(err.toString(), false);
child: ExceptionBottomSheet( // context.showBottomSheet(
message: err.toString(), // child: ExceptionBottomSheet(
showCancel: false, // message: err.toString(),
onOkPressed: () { // showCancel: false,
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
} }
} }
@ -918,14 +913,38 @@ class _RegisterNew extends State<RegisterNew> {
} }
startSMSService(type, skipRegistration) { startSMSService(type, skipRegistration) {
late SMSOTP smsOtp; // Declare the variable first late SMSOTP smsOtp;
smsOtp = SMSOTP( smsOtp = SMSOTP(
context, context,
type, type,
mobileNo, mobileNo,
(code) { (code) {
smsOtp.dispose(); checkActivationCode(
checkActivationCode(value: code, type: type, skipRegistration: skipRegistration); value: code,
type: type,
skipRegistration: skipRegistration,
onWrongActivationCode: (String? message, bool? isReroute) {
if (isReroute== true) {
context.showBottomSheet(
child: ExceptionBottomSheet(
message: message.toString(),
showCancel: false,
onOkPressed: () {
Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin));
},
),
);
} else {
context.showBottomSheet(
child: ExceptionBottomSheet(
message: message.toString(),
onOkPressed: () {
Navigator.of(context).pop();
},
),
);
}
});
}, },
() { () {
smsOtp.dispose(); // Now we can reference it smsOtp.dispose(); // Now we can reference it

@ -327,15 +327,15 @@ class _WelcomeLogin extends State<WelcomeLogin> {
if (value['isSMSSent']) if (value['isSMSSent'])
{ {
sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']),
this.loginTokenID = value['LogInTokenID'], loginTokenID = value['LogInTokenID'],
sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request),
// Future.delayed(Duration(seconds: 1), () { // Future.delayed(Duration(seconds: 1), () {
this.sendActivationCode(type) sendActivationCode(type)
// }) // })
} }
else else
{ {
if (value['IsAuthenticated']) {this.checkActivationCode()} if (value['IsAuthenticated']) {checkActivationCode(onWrongActivationCode: (String? message) {})}
} }
}) })
.catchError((err) { .catchError((err) {
@ -406,7 +406,7 @@ class _WelcomeLogin extends State<WelcomeLogin> {
} }
} }
Future<void> checkActivationCode({dynamic value}) async { Future<void> checkActivationCode({dynamic value, required Function(String? message) onWrongActivationCode}) async {
GifLoaderDialogUtils.showMyDialog(context); GifLoaderDialogUtils.showMyDialog(context);
final request = getCommonRequest().toJson(); final request = getCommonRequest().toJson();
dynamic res; dynamic res;
@ -428,14 +428,7 @@ class _WelcomeLogin extends State<WelcomeLogin> {
} }
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(result.toString());
child: ExceptionBottomSheet(
message: result.toString(),
onOkPressed: () {
Navigator.of(context).pop();
},
),
);
projectViewModel.analytics.loginRegistration.login_fail(error: result); projectViewModel.analytics.loginRegistration.login_fail(error: result);
projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result);
} }
@ -447,14 +440,15 @@ class _WelcomeLogin extends State<WelcomeLogin> {
final activation = CheckActivationCode.fromJson(result as Map<String, dynamic>); final activation = CheckActivationCode.fromJson(result as Map<String, dynamic>);
if (activation.errorCode == '699') { if (activation.errorCode == '699') {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(activation.errorEndUserMessage);
child: ExceptionBottomSheet( // context.showBottomSheet(
message: activation.errorEndUserMessage, // child: ExceptionBottomSheet(
onOkPressed: () { // message: activation.errorEndUserMessage,
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
return; return;
} else if (registerd_data?.isRegister == true) { } else if (registerd_data?.isRegister == true) {
Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew));
@ -476,28 +470,30 @@ class _WelcomeLogin extends State<WelcomeLogin> {
} }
} else { } else {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(result.toString());
child: ExceptionBottomSheet( // context.showBottomSheet(
message: result.toString(), // child: ExceptionBottomSheet(
onOkPressed: () { // message: result.toString(),
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
projectViewModel.analytics.loginRegistration.login_fail(error: result); projectViewModel.analytics.loginRegistration.login_fail(error: result);
projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result);
} }
} }
} catch (err) { } catch (err) {
GifLoaderDialogUtils.hideDialog(context); GifLoaderDialogUtils.hideDialog(context);
context.showBottomSheet( onWrongActivationCode(err.toString());
child: ExceptionBottomSheet( // context.showBottomSheet(
message: err.toString(), // child: ExceptionBottomSheet(
onOkPressed: () { // message: err.toString(),
Navigator.of(context).pop(); // onOkPressed: () {
}, // Navigator.of(context).pop();
), // },
); // ),
// );
} }
} }
@ -508,11 +504,24 @@ class _WelcomeLogin extends State<WelcomeLogin> {
type, type,
phoneNumber, phoneNumber,
(code) { (code) {
smsOtp.dispose(); // smsOtp.dispose();
checkActivationCode(value: code); checkActivationCode(
value: code,
onWrongActivationCode: (String? message) {
// smsOtp.pauseTimer();
context.showBottomSheet(
child: ExceptionBottomSheet(
message: message.toString(),
onOkPressed: () {
Navigator.of(context).pop();
// Don't resume timer here, let it continue naturally when user tries again
},
),
);
});
}, },
() { () {
smsOtp.dispose(); // smsOtp.dispose();
Navigator.pop(context); Navigator.pop(context);
}, },
); );

@ -422,8 +422,8 @@ class AuthProvider with ChangeNotifier {
requestN.healthId = requestN.patientobject!.eHealthIdField; requestN.healthId = requestN.patientobject!.eHealthIdField;
} }
requestN.dob =requestN.isHijri ==1 ? requestN.patientobject!.dateofBirth :dateFormat2.format(dateFormat.parse(requestN.patientobject!.strDateofBirth!)); requestN.dob = requestN.isHijri == 1 ? requestN.patientobject!.dateofBirth : dateFormat2.format(dateFormat.parse(requestN.patientobject!.strDateofBirth!));
requestN.isHijri =requestN.isHijri; requestN.isHijri = requestN.isHijri;
requestN.patientIdentificationID = requestN.patientobject!.patientIdentificationNo; requestN.patientIdentificationID = requestN.patientobject!.patientIdentificationNo;
requestN.patientMobileNumber = requestN.patientobject!.mobileNumber.toString(); requestN.patientMobileNumber = requestN.patientobject!.mobileNumber.toString();
requestN.logInTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); requestN.logInTokenID = await sharedPref.getString(LOGIN_TOKEN_ID);

@ -3509,6 +3509,7 @@ class TranslationBase {
String get enterPhoneDesc => localizedValues["enterPhoneDesc"][locale.languageCode]; String get enterPhoneDesc => localizedValues["enterPhoneDesc"][locale.languageCode];
String get otpVerfication => localizedValues["otpVerification"][locale.languageCode]; String get otpVerfication => localizedValues["otpVerification"][locale.languageCode];
String get submiT => localizedValues["submiT"][locale.languageCode]; String get submiT => localizedValues["submiT"][locale.languageCode];
String get notice => localizedValues["notice"][locale.languageCode];
String get readMore => localizedValues["readMore"][locale.languageCode]; String get readMore => localizedValues["readMore"][locale.languageCode];
String get showLess => localizedValues["showLess"][locale.languageCode]; String get showLess => localizedValues["showLess"][locale.languageCode];

@ -113,6 +113,8 @@ class SMSOTP {
Utils.changeAppLanguage(context: context); Utils.changeAppLanguage(context: context);
}, },
body: SafeArea( body: SafeArea(
top: false,
bottom: Platform.isIOS ? false : true,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 21, vertical: 20), padding: const EdgeInsets.symmetric(horizontal: 21, vertical: 20),
child: Column( child: Column(
@ -147,7 +149,6 @@ class SMSOTP {
pinTextAnimatedSwitcherDuration: Duration(milliseconds: 300), pinTextAnimatedSwitcherDuration: Duration(milliseconds: 300),
pinBoxRadius: 18, pinBoxRadius: 18,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
), ),
), ),
SizedBox(height: 30), SizedBox(height: 30),
@ -181,103 +182,6 @@ class SMSOTP {
}); });
}, },
); );
// return showDialog(
// context: context,
// barrierColor: Colors.black.withOpacity(0.63),
// builder: (context) {
// projectProvider = Provider.of(context);
//
// return Dialog(
// backgroundColor: Colors.white,
// shape: RoundedRectangleBorder(),
// insetPadding: EdgeInsets.only(left: 21, right: 21),
// child: StatefulBuilder(builder: (context, setState) {
// if (displayTime == '') {
// startTimer(setState);
// if (Platform.isAndroid ) {
// if (type == 1) checkSignature();
// else if(type == 4) _listenWhatsAppCode();
// }
// }
//
// return Container(
// padding: EdgeInsets.only(left: 21, right: 18, top: 39, bottom: 59),
// child: Column(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// SvgPicture.asset(
// type == 1 ? "assets/images/new/verify_sms.svg" : "assets/images/new/verify_whatsapp.svg",
// height: 50,
// width: 50,
// ),
// IconButton(
// padding: EdgeInsets.zero,
// icon: Icon(Icons.close),
// constraints: BoxConstraints(),
// onPressed: () {
// Navigator.pop(context);
//
// this.onFailure();
// },
// )
// ],
// ),
// SizedBox(height: 22),
// Text(
// TranslationBase.of(context).pleaseEnterTheVerificationCode + ' xxxxxxxx' + mobileNo.toString().substring(mobileNo.toString().length - 3),
// style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48),
// ),
// SizedBox(height: 18),
// Directionality(
// textDirection: TextDirection.ltr,
// child: Center(
// child: OTPWidget(
// autoFocus: true,
// controller: _pinPutController,
// defaultBorderColor: Color(0xffD8D8D8),
// maxLength: 4,
// onTextChanged: (text) {},
// pinBoxColor: Colors.white,
// onDone: (code) => _onOtpCallBack(code, false),
// textBorderColor: Color(0xffD8D8D8),
// pinBoxWidth: 60,
// pinBoxHeight: 60,
// pinTextStyle: TextStyle(
// fontSize: 24.0,
// color: Color(0xff2B353E),
// ),
// pinTextAnimatedSwitcherTransition: ProvidedPinBoxTextAnimation.scalingTransition,
// pinTextAnimatedSwitcherDuration: Duration(milliseconds: 300),
// pinBoxRadius: 10,
// keyboardType: TextInputType.number,
// ),
// ),
// ),
// SizedBox(height: 30),
// RichText(
// text: TextSpan(
// text: TranslationBase.of(context).validationMessage + '\n',
// style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48),
// children: <TextSpan>[
// TextSpan(
// text: displayTime,
// style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xffD02127), letterSpacing: -0.48),
// ),
// ],
// ),
// ),
// ],
// ),
// );
// }),
// );
// });
} }
TextStyle buildTextStyle() { TextStyle buildTextStyle() {
@ -289,26 +193,18 @@ class SMSOTP {
InputDecoration buildInputDecoration(BuildContext context) { InputDecoration buildInputDecoration(BuildContext context) {
return InputDecoration( return InputDecoration(
counterText: " ", counterText: " ",
// ts/images/password_icon.png
// contentPadding: EdgeInsets.only(top: 20, bottom: 20),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)), borderRadius: BorderRadius.all(Radius.circular(10)),
borderSide: BorderSide(color: Colors.black), borderSide: BorderSide(color: Colors.black),
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)), borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: Theme.of(context).primaryColor), borderSide: BorderSide(color: Theme.of(context).primaryColor),
), ),
errorBorder: OutlineInputBorder( errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)), borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: CustomColors.accentColor), borderSide: BorderSide(color: CustomColors.accentColor),
), ),
focusedErrorBorder: OutlineInputBorder( focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)), borderRadius: BorderRadius.all(Radius.circular(10.0)),
borderSide: BorderSide(color: CustomColors.accentColor), borderSide: BorderSide(color: CustomColors.accentColor),
@ -383,16 +279,42 @@ class SMSOTP {
_timer = null; _timer = null;
} }
static void hideSMSBox(context) { // New method for flexible timer handling - pause timer without disposing
Navigator.pop(context); void pauseTimer() {
_timer?.cancel();
_timer = null;
} }
_onOtpCallBack(String otpCode, bool isAutofill) { // Method to resume the timer from current remaining time
if (otpCode.length == 4) { void resumeTimer(setState) {
onSuccess(otpCode); if (!_isDisposed && remainingTime > 0) {
startTimer(setState);
}
}
// Method to reset timer to original time and restart
void resetTimer(setState, {int? newTime}) {
_timer?.cancel();
if (newTime != null) {
remainingTime = newTime;
} else {
remainingTime = 120; // Reset to original 2 minutes
}
if (!_isDisposed) {
startTimer(setState);
} }
} }
// Method to check if timer is currently running
bool isTimerRunning() {
return _timer != null && _timer!.isActive;
}
// Method to get current remaining time
int getCurrentRemainingTime() {
return remainingTime;
}
checkSignature() async { checkSignature() async {
SmsVerification.startListeningSms().then((message) { SmsVerification.startListeningSms().then((message) {
// setState(() { // setState(() {
@ -427,4 +349,14 @@ class SMSOTP {
return null; return null;
} }
} }
static void hideSMSBox(context) {
Navigator.pop(context);
}
_onOtpCallBack(String otpCode, bool isAutofill) {
if (otpCode.length == 4) {
onSuccess(otpCode);
}
}
} }

Loading…
Cancel
Save