diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml
index a4a050f..01bf7ed 100644
--- a/.idea/libraries/Flutter_Plugins.xml
+++ b/.idea/libraries/Flutter_Plugins.xml
@@ -4,6 +4,7 @@
+
@@ -14,7 +15,6 @@
-
diff --git a/android/.gradle/6.7.1/executionHistory/executionHistory.bin b/android/.gradle/6.7.1/executionHistory/executionHistory.bin
index c9bffc9..23cb2c6 100644
Binary files a/android/.gradle/6.7.1/executionHistory/executionHistory.bin and b/android/.gradle/6.7.1/executionHistory/executionHistory.bin differ
diff --git a/android/.gradle/6.7.1/executionHistory/executionHistory.lock b/android/.gradle/6.7.1/executionHistory/executionHistory.lock
index c32eadb..47ec79c 100644
Binary files a/android/.gradle/6.7.1/executionHistory/executionHistory.lock and b/android/.gradle/6.7.1/executionHistory/executionHistory.lock differ
diff --git a/android/.gradle/6.7.1/fileHashes/fileHashes.bin b/android/.gradle/6.7.1/fileHashes/fileHashes.bin
index cb2b8ee..6428e3a 100644
Binary files a/android/.gradle/6.7.1/fileHashes/fileHashes.bin and b/android/.gradle/6.7.1/fileHashes/fileHashes.bin differ
diff --git a/android/.gradle/6.7.1/fileHashes/fileHashes.lock b/android/.gradle/6.7.1/fileHashes/fileHashes.lock
index fc23058..8545592 100644
Binary files a/android/.gradle/6.7.1/fileHashes/fileHashes.lock and b/android/.gradle/6.7.1/fileHashes/fileHashes.lock differ
diff --git a/android/.gradle/6.7.1/javaCompile/javaCompile.lock b/android/.gradle/6.7.1/javaCompile/javaCompile.lock
index 38fa238..1d7116d 100644
Binary files a/android/.gradle/6.7.1/javaCompile/javaCompile.lock and b/android/.gradle/6.7.1/javaCompile/javaCompile.lock differ
diff --git a/android/.gradle/6.7.1/javaCompile/taskHistory.bin b/android/.gradle/6.7.1/javaCompile/taskHistory.bin
index 111076f..d317184 100644
Binary files a/android/.gradle/6.7.1/javaCompile/taskHistory.bin and b/android/.gradle/6.7.1/javaCompile/taskHistory.bin differ
diff --git a/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index b628813..f939955 100644
Binary files a/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/android/.gradle/buildOutputCleanup/outputFiles.bin b/android/.gradle/buildOutputCleanup/outputFiles.bin
index 5fb4994..14231bf 100644
Binary files a/android/.gradle/buildOutputCleanup/outputFiles.bin and b/android/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/android/local.properties b/android/local.properties
index 2ca74dc..8b1faab 100644
--- a/android/local.properties
+++ b/android/local.properties
@@ -1,5 +1,5 @@
sdk.dir=C:\\Users\\sarva\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\src\\flutter
-flutter.buildMode=debug
+flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1
\ No newline at end of file
diff --git a/lib/main.dart b/lib/main.dart
index e0ed8a8..6d94162 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,9 +1,8 @@
-import 'package:dyeus/screens/welcome_screen.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-
import 'constants.dart';
+import 'screens/welcome_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart
index ff12b25..87e68b5 100644
--- a/lib/screens/home_screen.dart
+++ b/lib/screens/home_screen.dart
@@ -1,6 +1,20 @@
+import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
-class HomeScreen extends StatelessWidget {
+class HomeScreen extends StatefulWidget {
+ @override
+ State createState() => _HomeScreenState();
+}
+
+class _HomeScreenState extends State {
+ FirebaseAuth _auth = FirebaseAuth.instance;
+
+ @override
+ void dispose() {
+ _auth.signOut();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
diff --git a/lib/screens/otp_verification.dart b/lib/screens/otp_verification.dart
index ab3cd72..c379296 100644
--- a/lib/screens/otp_verification.dart
+++ b/lib/screens/otp_verification.dart
@@ -1,6 +1,9 @@
+import 'dart:async';
+
import 'package:dyeus/services/firebase_auth_methods.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
+import 'package:fluttertoast/fluttertoast.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:sms_autofill/sms_autofill.dart';
@@ -24,6 +27,7 @@ class _OTPVerificationState extends State {
TextEditingController otpController;
FirebaseAuthMethods firebaseAuthMethod;
FirebaseAuth _auth = FirebaseAuth.instance;
+ UserCredential userCredential;
Widget bottomHelperOptions(screenHeight) {
if (buttonText == 'Done') {
@@ -62,44 +66,31 @@ class _OTPVerificationState extends State {
}
}
- void sendAndReadOTP() {
- firebaseAuthMethod = FirebaseAuthMethods(
+ void triggerFirebaseAuthVerification() async {
+ //todo: Make it future and await in case of error
+ await Future.sync(() {
+ firebaseAuthMethod = FirebaseAuthMethods(
context: context,
otpController: otpController,
otpCode: (value) {
setState(() {
otp = value;
});
- });
- }
-
- Future autoFillOTPAndVerifyUser() async {
- bool verify = await firebaseAuthMethod.phoneSignin(widget.phoneNumber);
- if (verify == true) {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => HomeScreen(),
- ),
+ },
);
- }
- }
-
- void verifyUserFromAutoDetectedOTP() async {
- sendAndReadOTP();
- await autoFillOTPAndVerifyUser();
- }
-
- Future verifyUserFromManuallyEnteredOTP() async {
- bool verify = await firebaseAuthMethod.verifyManuallyEnteredOtp();
- if (verify == true) {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => HomeScreen(),
- ),
- );
- }
+ });
+ userCredential = await firebaseAuthMethod.phoneSignIn(widget.phoneNumber);
+ _auth.authStateChanges().listen((user) {
+ if (user != null) {
+ Fluttertoast.showToast(msg: 'Verification Successful!');
+ Navigator.push(
+ context,
+ MaterialPageRoute(
+ builder: (context) => HomeScreen(),
+ ),
+ );
+ }
+ });
}
@override
@@ -107,8 +98,7 @@ class _OTPVerificationState extends State {
buttonText = 'Resend OTP';
otpController = TextEditingController();
startResendOTPTimer();
- sendAndReadOTP();
- autoFillOTPAndVerifyUser();
+ triggerFirebaseAuthVerification();
super.initState();
}
@@ -236,7 +226,6 @@ class _OTPVerificationState extends State {
),
onPressed: () async {
if (buttonText == 'Done') {
- await verifyUserFromManuallyEnteredOTP();
} else if (buttonText == 'Resend OTP' && resendOTPGap == 0) {
initState();
}
diff --git a/lib/services/firebase_auth_methods.dart b/lib/services/firebase_auth_methods.dart
index c28535b..225bbb4 100644
--- a/lib/services/firebase_auth_methods.dart
+++ b/lib/services/firebase_auth_methods.dart
@@ -12,42 +12,17 @@ class FirebaseAuthMethods {
FirebaseAuthMethods(
{@required this.context, @required this.otpController, this.otpCode});
- Future verifyManuallyEnteredOtp() async {
- bool success = false;
- PhoneAuthCredential credential;
- try {
- credential = PhoneAuthProvider.credential(
- verificationId: FirebaseAuthMethods.codeVerificationId,
- smsCode: otpController.text.trim(),
- );
- } catch (e) {
- Fluttertoast.showToast(msg: e.toString());
- }
- try {
- final user = await _auth.signInWithCredential(credential);
- if (user != null) {
- Fluttertoast.showToast(msg: 'Verification Successful!');
- success = true;
- }
- } catch (e) {
- Fluttertoast.showToast(msg: e.toString());
- }
- return success;
- }
-
- Future phoneSignin(String phoneNumber) async {
+ Future phoneSignIn(String phoneNumber) async {
String otp;
- bool success = false;
+ UserCredential userCredential;
await _auth.verifyPhoneNumber(
phoneNumber: '+91$phoneNumber',
verificationCompleted: (credential) async {
try {
final user = await _auth.signInWithCredential(credential);
- if (user != null) {
+ if (_auth.currentUser != null) {
otp = credential.smsCode;
otpCode = (otp) {};
- Fluttertoast.showToast(msg: 'Verified Successfully!');
- success = true;
}
} catch (e) {
Fluttertoast.showToast(msg: e);
@@ -57,11 +32,32 @@ class FirebaseAuthMethods {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(e.message)));
},
+ // autoRetrievedSmsCodeForTesting: '987654',
codeSent: (verificationId, resendToken) async {
- codeVerificationId = verificationId;
+ PhoneAuthCredential credential;
+ try {
+ credential = PhoneAuthProvider.credential(
+ verificationId: verificationId,
+ smsCode: otpController.text.trim(),
+ );
+ } catch (e) {
+ Fluttertoast.showToast(msg: e.toString() + 'ok');
+ }
+ try {
+ await _auth.signInWithCredential(credential);
+ } catch (e) {
+ Fluttertoast.showToast(msg: e.toString());
+ }
+ },
+ codeAutoRetrievalTimeout: (value) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: Text(
+ 'Unable to automatically read the code. Please enter it manually.'),
+ ),
+ );
},
- codeAutoRetrievalTimeout: (value) {},
);
- return success;
+ return userCredential;
}
}