Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌟 File Addition #16

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
}
},
"oauth_client": [
{
"client_id": "239407209167-6idtevr72g4p9p7ur5go8b1f4d29vsr1.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.freeguy.sort_it",
"certificate_hash": "a54352bb98332cc467f2f06b023e53d82ed7f990"
}
},
{
"client_id": "239407209167-rgr5e95mqvgfb29b3i2339su0f5vgvkf.apps.googleusercontent.com",
"client_type": 3
Expand Down
Binary file added assets/images/splash/1 (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/splash/1 (2).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/splash/1 (3).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/splash/1 (4).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/splash/1 (5).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/splash/1 (6).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/lottie/location.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions lib/controller/permission_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sort_it/src/screens/home/home.dart';

class PermissionController extends GetxController {
Future<void> getPermission(BuildContext context) async {
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
// Permission.phone,
// Permission.sms,
// Permission.camera,
].request();
if (await Permission.location.request().isGranted) {
print('location granted');
Fluttertoast.showToast(msg: "Permission Granted!");

///Push Named and remove Until Home Screen
Navigator.pushNamedAndRemoveUntil(
context, Home.routeName, (route) => false);
} else {
Fluttertoast.showToast(msg: "Permission Not Granted!");
}
}
}
2 changes: 1 addition & 1 deletion lib/controller/sign_in_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SignInController extends GetxController {
.set({
'name': username,
'email': email,
'image_url':null,
'image_url': null,
});

Fluttertoast.showToast(msg: 'Welcome $username!');
Expand Down
264 changes: 263 additions & 1 deletion lib/controller/sign_up_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:sms_autofill/sms_autofill.dart';
import 'package:sort_it/enum/enum.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SignUpController extends GetxController {
//-----------------VARIABLES----------------//
var passController = TextEditingController();
final _auth = FirebaseAuth.instance;
final userDb = FirebaseFirestore.instance;
RxString verificationId = ''.obs;
RxBool isLoading = false.obs;
RxBool isLoadingForOtp = false.obs;
RxString passError = ''.obs;
RxString password = ''.obs;
final phoneController = TextEditingController();
final otpController = TextEditingController();

MobileVerificationState currentState =
MobileVerificationState.SHOW_MOBILE_FORM_STATE;

init() async {
SmsAutoFill().listenForCode;
}

void setLoader({required bool newval}) {
isLoadingForOtp.value = newval;
}

String? validatePassword(String value) {
RegExp regex =
Expand All @@ -20,4 +45,241 @@ class SignUpController extends GetxController {
}
}
}

///-----------------------SignIn with Phone and OTP Request------------------///
signInWithPhone(BuildContext context) async {
await _auth.verifyPhoneNumber(
phoneNumber: '+91' + phoneController.text,
verificationCompleted: (verificationCompleted) async {
print("-----verification completed--------");
UserCredential result =
await _auth.signInWithCredential(verificationCompleted);
User? user = result.user;

if (user != null) {
DocumentSnapshot userCheck =
await userDb.collection("users").doc(user.uid).get();
if (userCheck.exists) {
print("---------user exists------------");

///navigate to access permissions page

} else {
String? token = await FirebaseMessaging.instance.getToken();
userDb.collection('users').doc(user.uid).set({
"id": user.uid,
"name": user.displayName,
"email": user.email,
"tokens": FieldValue.arrayUnion([token])
});

///Push to complete user profile

}
Fluttertoast.showToast(msg: 'Successfully signed in');
} else {
Fluttertoast.showToast(msg: 'Error signing in');
}
},
verificationFailed: (verificationFailed) {
print("-----------Login Failed-------");
},
codeSent: (verificationID, resendingToken) {
verificationId.value = verificationID;
currentState = MobileVerificationState.SHOW_OTP_FORM_STATE;
print("------code sent-----");
isLoadingForOtp.value = false;
},
codeAutoRetrievalTimeout: (codeAutoRetrievalTimeout) {
print("-----code retrieval--------");
},
);
}

OtpFillWidget(context) {
return Container(
padding: EdgeInsets.symmetric(
horizontal: 30.w,
vertical: 200.h,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: Form(
child: Column(
children: [
Text(
"OTP Verification",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline1,
),
Text.rich(
TextSpan(text: 'We have sent code at \n', children: [
TextSpan(
text: '+91${phoneController.text}',
style: const TextStyle(
fontWeight: FontWeight.w700, color: Colors.black87)),
const TextSpan(text: '\n please verify'),
]),
textAlign: TextAlign.center,
),
buildTimer(),
SizedBox(
height: 10.h,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: PinFieldAutoFill(
controller: otpController,
decoration: UnderlineDecoration(
textStyle: const TextStyle(fontSize: 20, color: Colors.black),
colorBuilder: FixedColorBuilder(Colors.black.withOpacity(0.3)),
),
currentCode: otpController.text,
onCodeSubmitted: (code) {},
onCodeChanged: (code) {
if (code!.length == 6) {
FocusScope.of(context).unfocus();

otpController.text = code;
isLoading.value = true;

PhoneAuthCredential phoneAuthCredential =
PhoneAuthProvider.credential(
verificationId: verificationId.value,
smsCode: otpController.text);
signInWithPhoneAuthCredential(phoneAuthCredential, context);
//FocusScope.of(context).requestFocus(FocusNode());
}
},
),
),
const SizedBox(
height: 10,
),
!isLoading.value
? ElevatedButton(
onPressed: () async {
PhoneAuthCredential phoneAuthCredential =
PhoneAuthProvider.credential(
verificationId: verificationId.value,
smsCode: otpController.text);
signInWithPhoneAuthCredential(phoneAuthCredential, context);
},
child: const Text('Verify'),
)
: const Center(
child: CircularProgressIndicator(),
),
],
)),
);
}

Row buildTimer() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//Text("This code will expired in "),
TweenAnimationBuilder(
tween: Tween(begin: 45.0, end: 0.0),
duration: const Duration(seconds: 45),
builder: (_, dynamic value, child) => Text(
"00:${value.toInt()}",
style: TextStyle(color: Colors.blue),
),
onEnd: () {},
),
],
);
}

void signInWithPhoneAuthCredential(
PhoneAuthCredential phoneAuthCredential, BuildContext context) async {
try {
final _authCredential =
await _auth.signInWithCredential(phoneAuthCredential);
User? user = _authCredential.user;
if (user != null) {
DocumentSnapshot userCheck =
await userDb.collection("users").doc(user.uid).get();
if (userCheck.exists) {
print("user existssssssssssssssssss");

// navigationService.navigateTo("/access-permission",
// withreplacement: true);

} else {
String? token = await FirebaseMessaging.instance.getToken();
userDb.collection('users').doc(user.uid).set({
"id": user.uid,
"name": user.displayName,
"email": user.email,
"tokens": FieldValue.arrayUnion([token])
});

Navigator.of(context).pushNamedAndRemoveUntil(
'/complete-profile', (Route<dynamic> route) => false);
}
Fluttertoast.showToast(msg: 'Successfully signed in');
} else {
Fluttertoast.showToast(msg: 'Error signing in');
}
} on FirebaseAuthException catch (e) {
print(e.message);
}
}

///----------------------------------Google SignIn--------------------------------///
// Future<User?> signInWithGoogle() async {
// final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// final GoogleSignInAuthentication googleSignInAuthentication =
// await googleUser!.authentication;
// final credential = GoogleAuthProvider.credential(
// accessToken: googleSignInAuthentication.accessToken,
// idToken: googleSignInAuthentication.idToken);
//
// //value has data of authenticated user
// final UserCredential userCred =
// await _auth.signInWithCredential(credential);
// final User? user = userCred.user;
//
// if (user != null) {
// DocumentSnapshot userCheck =
// await userDb.collection("users").doc(user.uid).get();
// if (userCheck.exists) {
// print("user existssssssssssssssssss");
// navigationService.navigateTo("/access-permission",
// withreplacement: true);
// } else {
// String? token = await FirebaseMessaging.instance.getToken();
// userDb.collection('users').doc(user.uid).set({
// "id": user.uid,
// "name": user.displayName,
// "email": user.email,
// "tokens": FieldValue.arrayUnion([token])
// });
// navigationService.navigateTo(
// "/complete-profile",
// withreplacement: true,
// );
// }
// Fluttertoast.showToast(msg:'Successfully Signed in');
// } else {
// Fluttertoast.showToast(msg:'Error signing in');
// }
//
// return user;
// }

///---------------------------------Facebook SignIn-----------------------------///
// Future signInWithFacebook() async {
// final LoginResult loginResult = await FacebookAuth.instance.login();
// final OAuthCredential facebookAuthCredential =
// FacebookAuthProvider.credential(loginResult.accessToken!.token);
//
// var user = await FirebaseAuth.instance
// .signInWithCredential(facebookAuthCredential);
// print(user);
// }
}
4 changes: 4 additions & 0 deletions lib/enum/enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum MobileVerificationState {
SHOW_MOBILE_FORM_STATE,
SHOW_OTP_FORM_STATE,
}
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MyApp extends StatelessWidget {
),
),
routes: routes,
initialRoute: SignUp.routeName,
initialRoute: Home.routeName,
),
),
);
Expand Down
23 changes: 23 additions & 0 deletions lib/service/navigation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

class NavigationService {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

Future navigateTo(String routeName,
{Object? arguments, bool withreplacement = false}) {
if (withreplacement) {
return navigatorKey.currentState!.pushNamedAndRemoveUntil(
routeName, (route) => false,
arguments: arguments);
} else {
return navigatorKey.currentState!
.pushNamed(routeName, arguments: arguments);
}
}

bool pop({required String routeName, Object? argument}) {
navigatorKey.currentState!.pop();

return true;
}
}
Loading