CHANGE_
This commit is contained in:
parent
ecc4dc9371
commit
aca02073a4
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.nhance_app_pwa">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.example.nhancepolicy
|
||||
package com.example.nhance_app_pwa
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
|
||||
23
lib/firebase-config.dart
Normal file
23
lib/firebase-config.dart
Normal file
@ -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<void> 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']!,
|
||||
),
|
||||
);
|
||||
}
|
||||
159
lib/hrLogin.dart
159
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<MyHrLogin> {
|
||||
TextEditingController countryController = TextEditingController();
|
||||
TextEditingController mobileController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||
|
||||
late String _verificationId;
|
||||
int? _resendToken;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -47,6 +54,9 @@ class _MyPhoneState extends State<MyHrLogin> {
|
||||
|
||||
Future<void> 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<MyHrLogin> {
|
||||
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<void> _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<MyHrLogin> {
|
||||
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)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -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<MyHrVerify> createState() => _MyVerifyState();
|
||||
@ -34,10 +46,24 @@ class _MyVerifyState extends State<MyHrVerify> {
|
||||
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<MyHrVerify> {
|
||||
}
|
||||
}
|
||||
|
||||
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<MyHrVerify> {
|
||||
}
|
||||
}
|
||||
|
||||
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<void> 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<MyHrVerify> {
|
||||
@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<MyHrVerify> {
|
||||
)
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
resendOTP(mobileNumber);
|
||||
_resendOTP();
|
||||
},
|
||||
child: Text(
|
||||
"Resend OTP",
|
||||
|
||||
@ -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<void> 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(),
|
||||
|
||||
147
lib/phone.dart
147
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<MyPhone> {
|
||||
TextEditingController countryController = TextEditingController();
|
||||
TextEditingController mobileController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||
|
||||
late String _verificationId;
|
||||
int? _resendToken;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -63,9 +70,10 @@ class _MyPhoneState extends State<MyPhone> {
|
||||
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<MyPhone> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<void> _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<MyPhone> {
|
||||
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)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -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<MyVerify> createState() => _MyVerifyState();
|
||||
@ -33,12 +45,25 @@ class _MyVerifyState extends State<MyVerify> {
|
||||
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<MyVerify> {
|
||||
}
|
||||
}
|
||||
|
||||
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<MyVerify> {
|
||||
}
|
||||
}
|
||||
|
||||
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<void> 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<MyVerify> {
|
||||
@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<MyVerify> {
|
||||
)
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
resendOTP(mobileNumber);
|
||||
_resendOTP();
|
||||
},
|
||||
child: Text(
|
||||
"Resend OTP",
|
||||
|
||||
@ -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"))
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -73,6 +73,26 @@
|
||||
<div id="loading_indicator" class="container overlay">
|
||||
<img class="indicator" src="assets/nhance-loader.gif">
|
||||
</div>
|
||||
<script type="module">
|
||||
// Import the functions you need from the SDKs you need
|
||||
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.4/firebase-app.js";
|
||||
// TODO: Add SDKs for Firebase products that you want to use
|
||||
// https://firebase.google.com/docs/web/setup#available-libraries
|
||||
|
||||
// Your web app's Firebase configuration
|
||||
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"
|
||||
};
|
||||
|
||||
|
||||
// Initialize Firebase
|
||||
const app = initializeApp(firebaseConfig);
|
||||
</script>
|
||||
<script>
|
||||
window.addEventListener('load', function(ev) {
|
||||
// Download main.dart.js
|
||||
|
||||
@ -6,10 +6,16 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <firebase_auth/firebase_auth_plugin_c_api.h>
|
||||
#include <firebase_core/firebase_core_plugin_c_api.h>
|
||||
#include <smart_auth/smart_auth_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
FirebaseAuthPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi"));
|
||||
FirebaseCorePluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
|
||||
SmartAuthPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("SmartAuthPlugin"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
firebase_auth
|
||||
firebase_core
|
||||
smart_auth
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user