From fe36c2a1c10c84d5e379b374bd183fc4030be9d8 Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Wed, 17 Sep 2025 15:48:28 +0300 Subject: [PATCH] auto sms --- .../authentication_view_model.dart | 12 ++++++++++- .../widgets/otp_verification_screen.dart | 20 ++++++++++++++++++- pubspec.yaml | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index bb41af6..73e1706 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:developer'; +import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart' show rootBundle; import 'package:flutter/material.dart'; @@ -36,6 +37,7 @@ import 'package:hmg_patient_app_new/services/localauth_service.dart'; import 'package:hmg_patient_app_new/services/navigation_service.dart'; import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart'; import 'package:hmg_patient_app_new/widgets/bottomsheet/exception_bottom_sheet.dart'; +import 'package:sms_otp_auto_verify/sms_otp_auto_verify.dart'; import 'models/request_models/get_user_mobile_device_data.dart'; import 'models/request_models/insert_patient_mobile_deviceinfo.dart'; @@ -355,7 +357,7 @@ class AuthenticationViewModel extends ChangeNotifier { ); // TODO: GET APP SMS SIGNATURE HERE - request.sMSSignature = "enKTDcqbOVd"; + request.sMSSignature =await getSignature(); if (checkIsUserComingForRegister(request: payload)) { _appState.setUserRegistrationPayload = RegistrationDataModelPayload.fromJson(payload); @@ -921,4 +923,12 @@ class AuthenticationViewModel extends ChangeNotifier { }, ); } + Future getSignature() async { + if (Platform.isAndroid) { + return await SmsVerification.getAppSignature(); + } else { + return null; + } + } + } diff --git a/lib/features/authentication/widgets/otp_verification_screen.dart b/lib/features/authentication/widgets/otp_verification_screen.dart index db7b1eb..8e77f81 100644 --- a/lib/features/authentication/widgets/otp_verification_screen.dart +++ b/lib/features/authentication/widgets/otp_verification_screen.dart @@ -9,6 +9,7 @@ import 'package:hmg_patient_app_new/core/utils/size_utils.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/app_bar_widget.dart'; +import 'package:sms_otp_auto_verify/sms_otp_auto_verify.dart'; typedef OnDone = void Function(String text); @@ -132,6 +133,7 @@ class OTPWidgetState extends State with SingleTickerProviderStateMixi widget.controller!.addListener(_controllerListener); } focusNode.addListener(_focusListener); + checkSignature(); } void _controllerListener() { @@ -209,7 +211,15 @@ class OTPWidgetState extends State with SingleTickerProviderStateMixi ], ); } - + void checkSignature() async { + SmsVerification.startListeningSms().then((message) { + final intRegex = RegExp(r'\d+', multiLine: true); + var otp = SmsVerification.getCode(message, intRegex); + widget.controller!.text = otp; + _onTextChanged(text); + SmsVerification.stopListening(); + }); + } Widget _touchPinBoxRow() { return widget.hideDefaultKeyboard ? _pinBoxRow(context) @@ -462,6 +472,7 @@ class _OTPVerificationScreenState extends State { super.initState(); _otpController = TextEditingController(); _startResendTimer(); + } @override @@ -506,6 +517,7 @@ class _OTPVerificationScreenState extends State { _startResendTimer(); // autoFillOtp("1234"); widget.onResendOTPPressed(widget.phoneNumber); + } } @@ -618,5 +630,11 @@ class _OTPVerificationScreenState extends State { if (otp.length != _otpLength) return; _isVerifying = false; _otpController.text = otp; + + setState(() { + + }); } + + } diff --git a/pubspec.yaml b/pubspec.yaml index 055fb7b..4e8d4ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -66,6 +66,7 @@ dependencies: firebase_analytics: ^11.5.1 jiffy: ^6.4.3 hijri_gregorian_calendar: ^0.1.1 + sms_otp_auto_verify: ^2.2.0 web: any flutter_staggered_animations: ^1.1.1