From aca02073a4edfcf8ad3b6ba1652a63d844ab1de0 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Sun, 28 Jul 2024 10:46:50 +0530 Subject: [PATCH] CHANGE_ --- android/app/build.gradle | 6 +- android/app/src/main/AndroidManifest.xml | 2 +- .../com/example/nhancepolicy/MainActivity.kt | 2 +- lib/firebase-config.dart | 23 +++ lib/hrLogin.dart | 159 +++++++++++++++--- lib/hrVerify.dart | 89 +++++++++- lib/main.dart | 24 ++- lib/phone.dart | 147 +++++++++++++--- lib/verify.dart | 87 +++++++++- macos/Flutter/GeneratedPluginRegistrant.swift | 6 + pubspec.yaml | 3 + web/index.html | 20 +++ .../flutter/generated_plugin_registrant.cc | 6 + windows/flutter/generated_plugins.cmake | 2 + 14 files changed, 502 insertions(+), 74 deletions(-) create mode 100644 lib/firebase-config.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 8c7f6c7..c3e63b3 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -23,7 +23,7 @@ if (flutterVersionName == null) { } android { - namespace "com.example.nhancepolicy" + namespace "com.example.nhance_app_pwa" compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -42,10 +42,10 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.nhancepolicy" + applicationId "com.example.nhance_app_pwa" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 23 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 957b86b..58fb080 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + diff --git a/android/app/src/main/kotlin/com/example/nhancepolicy/MainActivity.kt b/android/app/src/main/kotlin/com/example/nhancepolicy/MainActivity.kt index 501b396..7d8c50e 100644 --- a/android/app/src/main/kotlin/com/example/nhancepolicy/MainActivity.kt +++ b/android/app/src/main/kotlin/com/example/nhancepolicy/MainActivity.kt @@ -1,4 +1,4 @@ -package com.example.nhancepolicy +package com.example.nhance_app_pwa import io.flutter.embedding.android.FlutterActivity diff --git a/lib/firebase-config.dart b/lib/firebase-config.dart new file mode 100644 index 0000000..0a282fa --- /dev/null +++ b/lib/firebase-config.dart @@ -0,0 +1,23 @@ +import 'package:firebase_core/firebase_core.dart'; + +const firebaseConfig = { + 'apiKey': "AIzaSyAg0e5u7Piy6sWfgKl0C6D2XYyOakGB4wg", + 'authDomain': "push-notification-enrollment.firebaseapp.com", + 'projectId': "push-notification-enrollment", + 'storageBucket': "push-notification-enrollment.appspot.com", + 'messagingSenderId': "203846206303", + 'appId': "1:203846206303:web:292619fd22c24ff99b6cea", +}; + +Future initializeFirebase() async { + await Firebase.initializeApp( + options: FirebaseOptions( + apiKey: firebaseConfig['apiKey']!, + authDomain: firebaseConfig['authDomain']!, + projectId: firebaseConfig['projectId']!, + storageBucket: firebaseConfig['storageBucket']!, + messagingSenderId: firebaseConfig['messagingSenderId']!, + appId: firebaseConfig['appId']!, + ), + ); +} diff --git a/lib/hrLogin.dart b/lib/hrLogin.dart index ebd91b3..8a7eba1 100644 --- a/lib/hrLogin.dart +++ b/lib/hrLogin.dart @@ -1,8 +1,10 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:http/http.dart' as http; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; +import 'package:nhancepolicy/hrVerify.dart'; import 'package:nhancepolicy/models/environment.dart'; import 'dart:convert'; import 'dart:io'; @@ -22,6 +24,11 @@ class _MyPhoneState extends State { TextEditingController countryController = TextEditingController(); TextEditingController mobileController = TextEditingController(); final _formKey = GlobalKey(); + final FirebaseAuth _auth = FirebaseAuth.instance; + + late String _verificationId; + int? _resendToken; + bool _isLoading = false; @override void initState() { @@ -47,6 +54,9 @@ class _MyPhoneState extends State { Future verifyMobileNumber() async { try { + setState(() { + _isLoading = true; + }); var enteredMobileNumber = mobileController.text; final response = await http.post( Uri.parse(Environment.apiUrl + 'verifyHrWithMobileNumber'), @@ -61,39 +71,129 @@ class _MyPhoneState extends State { bool userVerification = data['data']['user_verification']; String message = data['data']['message']; if (userVerification) { - ToastHelper.showSuccessToast(context, message); - Navigator.pushNamed(context, 'hrVerify', - arguments: enteredMobileNumber); + _verifyPhoneNumber(); + // ToastHelper.showSuccessToast(context, message); + // Navigator.pushNamed(context, 'hrVerify', + // arguments: enteredMobileNumber); } else { + setState(() { + _isLoading = false; + }); ToastHelper.showErrorToast(context, message); print('Invalid mobile number'); } } else { + setState(() { + _isLoading = false; + }); ToastHelper.showErrorToast(context, 'Failed to verify mobile number'); throw Exception('Failed to verify mobile number'); } } catch (e) { + setState(() { + _isLoading = false; + }); print('Error: $e'); ToastHelper.showErrorToast(context, 'Something went wrong'); } } - // void handleSubmit() async { - // if (_formKey.currentState!.validate()) { - // // var enteredMobileNumber = countryController.text + mobileController.text; - // var enteredMobileNumber = mobileController.text; - // - // bool isValid = await verifyMobileNumber(enteredMobileNumber); - // - // if (isValid) { - // ToastHelper.showSuccessToast(context, 'Mobile No Verified...'); - // Navigator.pushNamed(context, 'hrVerify', - // arguments: enteredMobileNumber); - // } else { - // ToastHelper.showErrorToast(context, 'Invalid mobile number'); - // } - // } - // } + Future _verifyPhoneNumber() async { + var enteredMobileNumber = mobileController.text; + var countryCode = countryController.text; + print('${countryCode + enteredMobileNumber}'); + await _auth.verifyPhoneNumber( + phoneNumber: '${countryCode + enteredMobileNumber}', + timeout: const Duration(seconds: 60), + verificationCompleted: (PhoneAuthCredential credential) async { + await _auth.signInWithCredential(credential); + ToastHelper.showSuccessToast(context, 'Verified Successfully!'); + setState(() { + _isLoading = false; + }); + }, + verificationFailed: (FirebaseAuthException e) { + ToastHelper.showSuccessToast(context, 'Verification Failed!'); + if (e.code == 'invalid-phone-number') { + print('The provided phone number is not valid.'); + } + setState(() { + _isLoading = false; + }); + }, + codeSent: (String verificationId, int? resendToken) { + setState(() { + _verificationId = verificationId; + _resendToken = resendToken; + }); + ToastHelper.showSuccessToast( + context, 'Verification code sent to ${enteredMobileNumber}'); + setState(() { + _isLoading = false; + }); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MyHrVerify( + verificationId: _verificationId, + mobileNumber: enteredMobileNumber, + resendToken: _resendToken, + onResendCode: _resendCode, // Pass the phone number + ), + ), + ); + }, + codeAutoRetrievalTimeout: (String verificationId) { + setState(() { + _verificationId = verificationId; + }); + ToastHelper.showSuccessToast(context, 'Code auto-retrieval timed out.'); + setState(() { + _isLoading = false; + }); + }, + ); + } + + void _resendCode(String mobileNumber, int? resendToken) async { + await _auth.verifyPhoneNumber( + phoneNumber: '${countryController.text + mobileNumber}', + timeout: const Duration(seconds: 60), + forceResendingToken: resendToken, + verificationCompleted: (PhoneAuthCredential credential) async { + await _auth.signInWithCredential(credential); + }, + verificationFailed: (FirebaseAuthException e) { + if (e.code == 'invalid-phone-number') { + print('The provided phone number is not valid.'); + } + }, + codeSent: (String verificationId, int? resendToken) { + setState(() { + _verificationId = verificationId; + _resendToken = resendToken; + }); + ToastHelper.showSuccessToast( + context, 'Verification code resent to ${mobileNumber}'); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MyHrVerify( + verificationId: _verificationId, + mobileNumber: mobileNumber, + resendToken: _resendToken, + onResendCode: _resendCode, + ), + ), + ); + }, + codeAutoRetrievalTimeout: (String verificationId) { + setState(() { + _verificationId = verificationId; + }); + }, + ); + } @override Widget build(BuildContext context) { @@ -482,12 +582,21 @@ class _MyPhoneState extends State { BorderRadius.circular(10), ), ), - onPressed: verifyMobileNumber, - child: Text( - "Login With OTP", - style: TextStyle( - color: Color(0xFFFFFFFF)), - ), + onPressed: _isLoading + ? null + : verifyMobileNumber, + child: _isLoading + ? CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation< + Color>( + Color(0xFF00989E)), + ) + : Text( + "Login With OTP", + style: TextStyle( + color: Color(0xFFFFFFFF)), + ), ), ), ), diff --git a/lib/hrVerify.dart b/lib/hrVerify.dart index f933648..260ba27 100644 --- a/lib/hrVerify.dart +++ b/lib/hrVerify.dart @@ -1,3 +1,4 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; @@ -13,7 +14,18 @@ import 'package:nhancepolicy/responsive.dart'; import 'package:jwt_decode/jwt_decode.dart'; class MyHrVerify extends StatefulWidget { - const MyHrVerify({Key? key}) : super(key: key); + final String verificationId; + final String mobileNumber; + final int? resendToken; + final Function(String, int?) onResendCode; + + const MyHrVerify({ + Key? key, + required this.verificationId, + required this.mobileNumber, + required this.resendToken, + required this.onResendCode, + }) : super(key: key); @override State createState() => _MyVerifyState(); @@ -34,10 +46,24 @@ class _MyVerifyState extends State { dynamic clientLogo; dynamic empRefId; + late String verificationId; + late String mobileNumber; + final FirebaseAuth _auth = FirebaseAuth.instance; + bool _isLoading = false; + late String _verificationId; + @override void initState() { super.initState(); checkTokenAvailability(); + verificationId = widget.verificationId; + mobileNumber = widget.mobileNumber; + print('Received verificationId: $verificationId'); + print('Received mobileNumber: $mobileNumber'); + if (verificationId.isEmpty) { + // Handle the case where verificationId is not provided + Navigator.pop(context); + } // Start the timer when the widget is initialized startTimer(); } @@ -114,14 +140,17 @@ class _MyVerifyState extends State { } } - void verifyOTP(String otp) async { + void generateToken(bool otpVerifyStatus) async { // Retrieve the passed mobile number value - final String mobileNumber = - ModalRoute.of(context)!.settings.arguments as String; + // final String mobileNumber = + // ModalRoute.of(context)!.settings.arguments as String; try { final response = await http.post( Uri.parse(Environment.apiUrl + 'getVerifiedHrData'), - body: json.encode({'mobile_number': mobileNumber, 'otp': otp}), + body: json.encode({ + 'mobile_number': mobileNumber, + 'otp_verification': otpVerifyStatus + }), headers: { HttpHeaders.contentTypeHeader: 'application/json', }, @@ -193,6 +222,50 @@ class _MyVerifyState extends State { } } + void verifyOTP(String otp) async { + try { + setState(() { + _isLoading = true; + }); + PhoneAuthCredential credential = PhoneAuthProvider.credential( + verificationId: verificationId, + smsCode: otp, + ); + + await FirebaseAuth.instance + .signInWithCredential(credential) + .then((user) async { + if (user != null) { + // Handle successful verification + ToastHelper.showSuccessToast(context, 'Successfully Login...!'); + bool otpVerifyStatus = true; + generateToken(otpVerifyStatus); + } else { + setState(() { + _isLoading = false; + }); + ToastHelper.showErrorToast(context, 'Invalid OTP. Please try again'); + } + }); + } catch (e) { + setState(() { + _isLoading = false; + }); + print('Error: $e'); + ToastHelper.showErrorToast( + context, 'Failed to verify OTP. Please try again.'); + } + } + + void _resendOTP() { + setState(() { + _secondsRemaining = 60; + _isTimerRunning = true; + }); + startTimer(); + widget.onResendCode(widget.mobileNumber, widget.resendToken); + } + Future getClientLogoAndDetails() async { var url = Uri.parse(Environment.apiUrl + 'getClientDetails?client_id=$client_id&client_branch_id=$empRefId'); @@ -243,8 +316,8 @@ class _MyVerifyState extends State { @override Widget build(BuildContext context) { // Retrieve the passed mobile number value - final String mobileNumber = - ModalRoute.of(context)!.settings.arguments as String; + // final String mobileNumber = + // ModalRoute.of(context)!.settings.arguments as String; Size _size = MediaQuery.of(context).size; EdgeInsets marginInsets = EdgeInsets.zero; if (Responsive.isDesktop(context)) { @@ -537,7 +610,7 @@ class _MyVerifyState extends State { ) : InkWell( onTap: () { - resendOTP(mobileNumber); + _resendOTP(); }, child: Text( "Resend OTP", diff --git a/lib/main.dart b/lib/main.dart index e7d69cf..11e10ea 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,20 +14,38 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:nhancepolicy/hrLogin.dart'; import 'package:nhancepolicy/hrPolicyDetails.dart'; import 'package:nhancepolicy/oldPolicy.dart'; +import 'package:firebase_core/firebase_core.dart'; Future main() async { // await dotenv.load(fileName: Environment.fileName); + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp( + options: const FirebaseOptions( + apiKey: 'AIzaSyAdacw5svpqopDCpoEym7aDkI3F2AajEO4', + appId: '1:203846206303:android:01f39a22f39a50539b6cea', + messagingSenderId: '203846206303', + projectId: 'push-notification-enrollment')); await dotenv.load(fileName: Environment.fileName); runApp(MaterialApp( - initialRoute: 'phone', + initialRoute: 'hrLogin', debugShowCheckedModeBanner: false, routes: { 'phone': (context) => MyPhone(), - 'verify': (context) => MyVerify(), + 'verify': (context) => MyVerify( + verificationId: '', + mobileNumber: '', + resendToken: null, + onResendCode: (String, int) {}, + ), 'home': (context) => MyApp(), 'hrLogin': (context) => MyHrLogin(), - 'hrVerify': (context) => MyHrVerify(), + 'hrVerify': (context) => MyHrVerify( + verificationId: '', + mobileNumber: '', + resendToken: null, + onResendCode: (String, int) {}, + ), 'hrHome': (context) => MyHrHome(), 'excelVerify': (context) => excelVerify(), 'empDetails': (context) => empDetails(), diff --git a/lib/phone.dart b/lib/phone.dart index 4e3c5d1..123a7d6 100644 --- a/lib/phone.dart +++ b/lib/phone.dart @@ -1,3 +1,4 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -7,6 +8,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:nhancepolicy/responsive.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; +import 'package:nhancepolicy/verify.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_animated_button/flutter_animated_button.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -22,6 +24,11 @@ class _MyPhoneState extends State { TextEditingController countryController = TextEditingController(); TextEditingController mobileController = TextEditingController(); final _formKey = GlobalKey(); + final FirebaseAuth _auth = FirebaseAuth.instance; + + late String _verificationId; + int? _resendToken; + bool _isLoading = false; @override void initState() { @@ -63,9 +70,10 @@ class _MyPhoneState extends State { bool userVerification = data['data']['user_verification']; String message = data['data']['message']; if (userVerification) { - ToastHelper.showSuccessToast(context, message); - Navigator.pushNamed(context, 'verify', - arguments: enteredMobileNumber); + // ToastHelper.showSuccessToast(context, message); + _verifyPhoneNumber(); + // Navigator.pushNamed(context, 'verify', + // arguments: enteredMobileNumber); } else { ToastHelper.showErrorToast(context, message); print('Invalid mobile number'); @@ -81,22 +89,102 @@ class _MyPhoneState extends State { } } - // void handleSubmit() async { - // if (_formKey.currentState!.validate()) { - // // var enteredMobileNumber = countryController.text + mobileController.text; - // var enteredMobileNumber = mobileController.text; - // - // bool isValid = await verifyMobileNumber(enteredMobileNumber); - // - // if (isValid) { - // ToastHelper.showSuccessToast(context, 'Mobile No Verified..'); - // Navigator.pushNamed(context, 'verify', arguments: enteredMobileNumber); - // } else { - // ToastHelper.showErrorToast(context, 'Invalid mobile number..'); - // print('Invalid mobile number'); - // } - // } - // } + Future _verifyPhoneNumber() async { + var enteredMobileNumber = mobileController.text; + var countryCode = countryController.text; + print('${countryCode + enteredMobileNumber}'); + await _auth.verifyPhoneNumber( + phoneNumber: '${countryCode + enteredMobileNumber}', + timeout: const Duration(seconds: 60), + verificationCompleted: (PhoneAuthCredential credential) async { + await _auth.signInWithCredential(credential); + ToastHelper.showSuccessToast(context, 'Verified Successfully!'); + setState(() { + _isLoading = false; + }); + }, + verificationFailed: (FirebaseAuthException e) { + ToastHelper.showSuccessToast(context, 'Verification Failed!'); + if (e.code == 'invalid-phone-number') { + print('The provided phone number is not valid.'); + } + setState(() { + _isLoading = false; + }); + }, + codeSent: (String verificationId, int? resendToken) { + setState(() { + _verificationId = verificationId; + _resendToken = resendToken; + }); + ToastHelper.showSuccessToast( + context, 'Verification code sent to ${enteredMobileNumber}'); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MyVerify( + verificationId: _verificationId, + mobileNumber: enteredMobileNumber, + resendToken: _resendToken, + onResendCode: _resendCode, // Pass the phone number + ), + ), + ); + setState(() { + _isLoading = false; + }); + }, + codeAutoRetrievalTimeout: (String verificationId) { + setState(() { + _verificationId = verificationId; + }); + ToastHelper.showSuccessToast(context, 'Code auto-retrieval timed out.'); + setState(() { + _isLoading = false; + }); + }, + ); + } + + void _resendCode(String mobileNumber, int? resendToken) async { + await _auth.verifyPhoneNumber( + phoneNumber: '${countryController.text + mobileNumber}', + timeout: const Duration(seconds: 60), + forceResendingToken: resendToken, + verificationCompleted: (PhoneAuthCredential credential) async { + await _auth.signInWithCredential(credential); + }, + verificationFailed: (FirebaseAuthException e) { + if (e.code == 'invalid-phone-number') { + print('The provided phone number is not valid.'); + } + }, + codeSent: (String verificationId, int? resendToken) { + setState(() { + _verificationId = verificationId; + _resendToken = resendToken; + }); + ToastHelper.showSuccessToast( + context, 'Verification code resent to ${mobileNumber}'); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => MyVerify( + verificationId: _verificationId, + mobileNumber: mobileNumber, + resendToken: _resendToken, + onResendCode: _resendCode, + ), + ), + ); + }, + codeAutoRetrievalTimeout: (String verificationId) { + setState(() { + _verificationId = verificationId; + }); + }, + ); + } @override Widget build(BuildContext context) { @@ -465,12 +553,21 @@ class _MyPhoneState extends State { BorderRadius.circular(10), ), ), - onPressed: verifyMobileNumber, - child: Text( - "Login With OTP", - style: GoogleFonts.poppins( - color: Color(0xFFFFFFFF)), - ), + onPressed: _isLoading + ? null + : verifyMobileNumber, + child: _isLoading + ? CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation< + Color>( + Color(0xFF00989E)), + ) + : Text( + "Login With OTP", + style: GoogleFonts.poppins( + color: Color(0xFFFFFFFF)), + ), ), ), ), diff --git a/lib/verify.dart b/lib/verify.dart index f3684b3..0f412ac 100644 --- a/lib/verify.dart +++ b/lib/verify.dart @@ -1,3 +1,4 @@ +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:nhancepolicy/models/environment.dart'; @@ -13,7 +14,18 @@ import 'package:jwt_decode/jwt_decode.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; class MyVerify extends StatefulWidget { - const MyVerify({Key? key}) : super(key: key); + final String verificationId; + final String mobileNumber; + final int? resendToken; + final Function(String, int?) onResendCode; + + const MyVerify({ + Key? key, + required this.verificationId, + required this.mobileNumber, + required this.resendToken, + required this.onResendCode, + }) : super(key: key); @override State createState() => _MyVerifyState(); @@ -33,12 +45,25 @@ class _MyVerifyState extends State { dynamic clientName; dynamic clientLogo; dynamic empClientBranchId; + late String verificationId; + late String mobileNumber; + final FirebaseAuth _auth = FirebaseAuth.instance; + bool _isLoading = false; + late String _verificationId; @override void initState() { super.initState(); checkTokenAvailability(); // Start the timer when the widget is initialized + verificationId = widget.verificationId; + mobileNumber = widget.mobileNumber; + print('Received verificationId: $verificationId'); + print('Received mobileNumber: $mobileNumber'); + if (verificationId.isEmpty) { + // Handle the case where verificationId is not provided + Navigator.pop(context); + } startTimer(); } @@ -106,14 +131,16 @@ class _MyVerifyState extends State { } } - void verifyOTP(String otp) async { + void generateToken(bool otpVerifyStatus) async { // Retrieve the passed mobile number value - final String mobileNumber = - ModalRoute.of(context)!.settings.arguments as String; + try { final response = await http.post( Uri.parse(Environment.apiUrl + 'getVerifiedUserData'), - body: json.encode({'mobile_number': mobileNumber, 'otp': otp}), + body: json.encode({ + 'mobile_number': mobileNumber, + 'otp_verification': otpVerifyStatus + }), headers: { HttpHeaders.contentTypeHeader: 'application/json', }, @@ -179,6 +206,50 @@ class _MyVerifyState extends State { } } + void verifyOTP(String otp) async { + try { + setState(() { + _isLoading = true; + }); + PhoneAuthCredential credential = PhoneAuthProvider.credential( + verificationId: verificationId, + smsCode: otp, + ); + + await FirebaseAuth.instance + .signInWithCredential(credential) + .then((user) async { + if (user != null) { + // Handle successful verification + ToastHelper.showSuccessToast(context, 'Successfully Login...!'); + bool otpVerifyStatus = true; + generateToken(otpVerifyStatus); + } else { + setState(() { + _isLoading = false; + }); + ToastHelper.showErrorToast(context, 'Invalid OTP. Please try again'); + } + }); + } catch (e) { + setState(() { + _isLoading = false; + }); + print('Error: $e'); + ToastHelper.showErrorToast( + context, 'Failed to verify OTP. Please try again.'); + } + } + + void _resendOTP() { + setState(() { + _secondsRemaining = 60; + _isTimerRunning = true; + }); + startTimer(); + widget.onResendCode(widget.mobileNumber, widget.resendToken); + } + Future getClientLogoAndDetails() async { var url = Uri.parse(Environment.apiUrl + 'getClientDetails?client_id=$client_id&emp_code=$empCodeString&client_branch_id=$empClientBranchId'); @@ -229,8 +300,8 @@ class _MyVerifyState extends State { @override Widget build(BuildContext context) { // Retrieve the passed mobile number value - final String mobileNumber = - ModalRoute.of(context)!.settings.arguments as String; + // final String mobileNumber = + // ModalRoute.of(context)!.settings.arguments as String; Size _size = MediaQuery.of(context).size; EdgeInsets marginInsets = EdgeInsets.zero; if (Responsive.isDesktop(context)) { @@ -506,7 +577,7 @@ class _MyVerifyState extends State { ) : InkWell( onTap: () { - resendOTP(mobileNumber); + _resendOTP(); }, child: Text( "Resend OTP", diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 48b0136..2ce5852 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,12 +5,18 @@ import FlutterMacOS import Foundation +import firebase_auth +import firebase_core +import google_sign_in_ios import path_provider_foundation import shared_preferences_foundation import smart_auth import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) + FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin")) diff --git a/pubspec.yaml b/pubspec.yaml index ef4dfac..3171e39 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -54,6 +54,9 @@ dependencies: spreadsheet_decoder: ^2.2.0 url_launcher: ^6.2.6 font_awesome_flutter: ^10.7.0 + firebase_auth: ^5.1.2 + google_sign_in: ^6.2.1 + firebase_auth_web: ^5.12.4 dev_dependencies: diff --git a/web/index.html b/web/index.html index 885e90d..00cdbf4 100644 --- a/web/index.html +++ b/web/index.html @@ -73,6 +73,26 @@
+