Starting SignInWithGoogle 🔨
continuous-integration/drone/push Build is passing Details

pull/57/head
Emre KARTAL 2 years ago
parent ebc09e5969
commit 75ca7ba086

@ -30,14 +30,18 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
handleRegister() async { handleRegister() async {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
try { try {
await MyApp.userViewModel.register(_userPseudoTextField.text, _passwordTextField.text, _userMailTextField.text); await MyApp.userViewModel.register(_userPseudoTextField.text,
_passwordTextField.text, _userMailTextField.text);
Navigator.pushNamed(context, '/explanation'); Navigator.pushNamed(context, '/explanation');
} catch (e) { } catch (e) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
e.toString() ?? "", e.toString() ?? "",
style: GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w400, fontSize: 20.h), style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 20.h),
), ),
backgroundColor: Colors.red, backgroundColor: Colors.red,
), ),
@ -46,6 +50,11 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
} }
} }
signInWithGoogle() async {
await MyApp.userViewModel.signInWithGoogle();
//Navigator.pushNamed(context, '/explanation');
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -63,8 +72,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
padding: EdgeInsets.only(top: 100.h), padding: EdgeInsets.only(top: 100.h),
child: AutoSizeText( child: AutoSizeText(
"On a besoin de ça!", "On a besoin de ça!",
style: style: GoogleFonts.plusJakartaSans(
GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.w600, fontSize: 30.w), color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 30.w),
maxLines: 1, maxLines: 1,
maxFontSize: 50, maxFontSize: 50,
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
@ -76,7 +87,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: defaultPadding), padding: EdgeInsets.symmetric(
horizontal: defaultPadding),
child: Padding( child: Padding(
padding: EdgeInsets.only(bottom: 50.h), padding: EdgeInsets.only(bottom: 50.h),
child: Column( child: Column(
@ -90,7 +102,9 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: AutoSizeText( child: AutoSizeText(
"Promis cest rapide.", "Promis cest rapide.",
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 17.w), color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 17.w),
maxFontSize: 20, maxFontSize: 20,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
@ -100,7 +114,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
), ),
), ),
Padding( Padding(
padding: EdgeInsets.only(bottom: 16.h, left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _userPseudoTextField, controller: _userPseudoTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
@ -112,24 +129,37 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(color: primaryColor, fontSize: 15), style: GoogleFonts.plusJakartaSans(
color: primaryColor, fontSize: 15),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1.sp, color: strokeTextField), borderSide: BorderSide(
borderRadius: const BorderRadius.all(Radius.circular(10))), width: 1.sp,
prefix: const Padding(padding: EdgeInsets.only(left: 20.0)), color: strokeTextField),
suffix: const Padding(padding: EdgeInsets.only(left: 20.0)), borderRadius: const BorderRadius.all(
Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
focusColor: const Color.fromRGBO(255, 255, 255, 0.30), focusColor: const Color.fromRGBO(
255, 255, 255, 0.30),
enabledBorder: const OutlineInputBorder( enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
hintText: 'Pseudo', hintText: 'Pseudo',
hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField)), hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField)),
)), )),
Padding( Padding(
padding: EdgeInsets.only(bottom: 16.h, left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _userMailTextField, controller: _userMailTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
@ -141,24 +171,36 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(color: primaryColor), style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
prefix: const Padding(padding: EdgeInsets.only(left: 20.0)), borderRadius: BorderRadius.all(
suffix: const Padding(padding: EdgeInsets.only(left: 20.0)), Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30), focusColor:
Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
borderRadius: BorderRadius.all(
Radius.circular(10))),
hintText: 'Email', hintText: 'Email',
hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField)), hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField)),
)), )),
Padding( Padding(
padding: EdgeInsets.only(bottom: 16.h, left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _passwordTextField, controller: _passwordTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
@ -170,21 +212,29 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
return null; return null;
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
style: GoogleFonts.plusJakartaSans(color: primaryColor), style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
prefix: const Padding(padding: EdgeInsets.only(left: 20.0)), borderRadius:
suffix: const Padding(padding: EdgeInsets.only(left: 20.0)), BorderRadius.all(Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30), focusColor: Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
borderRadius:
BorderRadius.all(Radius.circular(10))),
hintText: 'Mot de passe', hintText: 'Mot de passe',
hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField), hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField),
suffixIcon: Container( suffixIcon: Container(
padding: EdgeInsets.only(right: 10), padding: EdgeInsets.only(right: 10),
margin: EdgeInsets.all(5), margin: EdgeInsets.all(5),
@ -204,8 +254,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
// Splash color over image // Splash color over image
child: Image( child: Image(
image: passenable image: passenable
? AssetImage("assets/images/show_icon.png") ? AssetImage(
: AssetImage("assets/images/hide_icon.png"), "assets/images/show_icon.png")
: AssetImage(
"assets/images/hide_icon.png"),
height: 2, height: 2,
), ),
)), )),
@ -213,7 +265,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
), ),
), ),
Padding( Padding(
padding: EdgeInsets.only(bottom: 16.h, left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
bottom: 16.h,
left: defaultPadding,
right: defaultPadding),
child: TextFormField( child: TextFormField(
controller: _passwordConfirmTextField, controller: _passwordConfirmTextField,
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
@ -228,21 +283,29 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
}, },
cursorColor: primaryColor, cursorColor: primaryColor,
keyboardType: TextInputType.emailAddress, keyboardType: TextInputType.emailAddress,
style: GoogleFonts.plusJakartaSans(color: primaryColor), style: GoogleFonts.plusJakartaSans(
color: primaryColor),
decoration: InputDecoration( decoration: InputDecoration(
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
prefix: const Padding(padding: EdgeInsets.only(left: 20.0)), borderRadius:
suffix: const Padding(padding: EdgeInsets.only(left: 20.0)), BorderRadius.all(Radius.circular(10))),
prefix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
suffix: const Padding(
padding: EdgeInsets.only(left: 20.0)),
fillColor: bgTextField, fillColor: bgTextField,
filled: true, filled: true,
focusColor: Color.fromRGBO(255, 255, 255, 0.30), focusColor: Color.fromRGBO(255, 255, 255, 0.30),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: strokeTextField), borderSide: BorderSide(
borderRadius: BorderRadius.all(Radius.circular(10))), width: 1, color: strokeTextField),
borderRadius:
BorderRadius.all(Radius.circular(10))),
hintText: 'Confirmation du Mot de passe', hintText: 'Confirmation du Mot de passe',
hintStyle: GoogleFonts.plusJakartaSans(color: strokeTextField), hintStyle: GoogleFonts.plusJakartaSans(
color: strokeTextField),
suffixIcon: Container( suffixIcon: Container(
padding: EdgeInsets.only(right: 10), padding: EdgeInsets.only(right: 10),
margin: EdgeInsets.all(5), margin: EdgeInsets.all(5),
@ -262,8 +325,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
// Splash color over image // Splash color over image
child: Image( child: Image(
image: passenable image: passenable
? AssetImage("assets/images/show_icon.png") ? AssetImage(
: AssetImage("assets/images/hide_icon.png"), "assets/images/show_icon.png")
: AssetImage(
"assets/images/hide_icon.png"),
height: 2, height: 2,
), ),
)), )),
@ -271,7 +336,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
), ),
), ),
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: defaultPadding), padding: EdgeInsets.symmetric(
horizontal: defaultPadding),
child: SizedBox( child: SizedBox(
width: 600, width: 600,
child: LoginButton( child: LoginButton(
@ -291,12 +357,16 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
text: TextSpan( text: TextSpan(
text: 'Tu as déjà un compte?', text: 'Tu as déjà un compte?',
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 15), color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15),
children: <TextSpan>[ children: <TextSpan>[
TextSpan( TextSpan(
text: " Connexion", text: " Connexion",
style: GoogleFonts.plusJakartaSans( style: GoogleFonts.plusJakartaSans(
fontSize: 15, fontWeight: FontWeight.w400, color: primaryColor)), fontSize: 15,
fontWeight: FontWeight.w400,
color: primaryColor)),
], ],
), ),
), ),
@ -318,10 +388,13 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.only(left: defaultPadding, right: defaultPadding), padding: const EdgeInsets.only(
left: defaultPadding, right: defaultPadding),
child: Text( child: Text(
'Ou', 'Ou',
style: GoogleFonts.plusJakartaSans(color: Colors.white, fontWeight: FontWeight.bold), style: GoogleFonts.plusJakartaSans(
color: Colors.white,
fontWeight: FontWeight.bold),
), ),
), ),
Expanded( Expanded(
@ -341,8 +414,10 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: SignInButton( child: SignInButton(
Buttons.Google, Buttons.Google,
text: "Login with Google", text: "Login with Google",
onPressed: () {}, onPressed: signInWithGoogle,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))), shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20))),
), ),
), ),
), ),
@ -353,10 +428,13 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: Container( child: Container(
height: 240.h, height: 240.h,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(begin: Alignment.topRight, stops: [
begin: Alignment.topRight, 0,
stops: [0, 1], 1
colors: [bgColor.withOpacity(1), bgColor.withOpacity(0)])), ], colors: [
bgColor.withOpacity(1),
bgColor.withOpacity(0)
])),
), ),
), ),
Align( Align(
@ -364,7 +442,8 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 800), constraints: BoxConstraints(maxWidth: 800),
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 45.h, left: defaultPadding, right: defaultPadding), padding: EdgeInsets.only(
top: 45.h, left: defaultPadding, right: defaultPadding),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
child: LinearProgressIndicator( child: LinearProgressIndicator(

@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:google_sign_in/google_sign_in.dart';
import '../main.dart'; import '../main.dart';
class AuthService { class AuthService {
@ -52,6 +53,19 @@ class AuthService {
} }
} }
signInWithGoogle() async {
final GoogleSignInAccount? gUser = await GoogleSignIn().signIn();
final GoogleSignInAuthentication gAuth = await gUser!.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: gAuth.accessToken,
idToken: gAuth.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential);
}
Future<String> generateUniqueId(String pseudo) async { Future<String> generateUniqueId(String pseudo) async {
String uniqueId = '$pseudo#0001'; String uniqueId = '$pseudo#0001';
int suffix = 1; int suffix = 1;
@ -103,7 +117,6 @@ class AuthService {
await currentUser?.delete(); await currentUser?.delete();
await FirebaseAuth.instance.signOut(); await FirebaseAuth.instance.signOut();
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
if (e.code == 'requires-recent-login') { if (e.code == 'requires-recent-login') {
throw ('Please log in again to delete your account'); throw ('Please log in again to delete your account');

@ -12,7 +12,7 @@ import '../main.dart';
class UserViewModel { class UserViewModel {
late User _userCurrent; late User _userCurrent;
final AuthService authService = AuthService(); final AuthService _authService = AuthService();
final UserService _userService = UserService(); final UserService _userService = UserService();
User get userCurrent => _userCurrent; User get userCurrent => _userCurrent;
@ -34,7 +34,7 @@ class UserViewModel {
login(String pseudo, String password) async { login(String pseudo, String password) async {
try { try {
var token; var token;
await authService.login(pseudo, password); await _authService.login(pseudo, password);
await updateUserCurrent(); await updateUserCurrent();
if (!kIsWeb) { if (!kIsWeb) {
token = await FirebaseMessaging.instance.getToken(); token = await FirebaseMessaging.instance.getToken();
@ -72,13 +72,17 @@ class UserViewModel {
} }
try { try {
await authService.register(pseudo.toLowerCase(), email, password); await _authService.register(pseudo.toLowerCase(), email, password);
await updateUserCurrent(); await updateUserCurrent();
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
} }
signInWithGoogle() async {
await _authService.signInWithGoogle();
}
Future<List<User>> getUsersByUniqueId(String uniqueId) async { Future<List<User>> getUsersByUniqueId(String uniqueId) async {
try { try {
var response = var response =
@ -102,11 +106,11 @@ class UserViewModel {
} }
logout() { logout() {
authService.signOut(); _authService.signOut();
} }
delete() { delete() {
authService.delete(); _authService.delete();
} }
bool isFriend(String id) { bool isFriend(String id) {
@ -116,7 +120,7 @@ class UserViewModel {
updateImage(File pp) async { updateImage(File pp) async {
try { try {
await _userService.updateImage(pp); await _userService.updateImage(pp);
} catch(e) { } catch (e) {
print(e.toString()); print(e.toString());
rethrow; rethrow;
} }
@ -125,7 +129,7 @@ class UserViewModel {
updatePseudo(String pseudo) async { updatePseudo(String pseudo) async {
try { try {
await _userService.updatePseudo(pseudo); await _userService.updatePseudo(pseudo);
} catch(e) { } catch (e) {
print(e.toString()); print(e.toString());
rethrow; rethrow;
} }

@ -608,6 +608,54 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.0.4" version: "4.0.4"
google_identity_services_web:
dependency: transitive
description:
name: google_identity_services_web
sha256: "7940fdc3b1035db4d65d387c1bdd6f9574deaa6777411569c05ecc25672efacd"
url: "https://pub.dev"
source: hosted
version: "0.2.1"
google_sign_in:
dependency: "direct main"
description:
name: google_sign_in
sha256: aab6fdc41374014494f9e9026b9859e7309639d50a0bf4a2a412467a5ae4abc6
url: "https://pub.dev"
source: hosted
version: "6.1.4"
google_sign_in_android:
dependency: transitive
description:
name: google_sign_in_android
sha256: "8d60a787b29cb7d2bcf29230865f4a91f17323c6ac5b6b9027a6418e48d9ffc3"
url: "https://pub.dev"
source: hosted
version: "6.1.18"
google_sign_in_ios:
dependency: transitive
description:
name: google_sign_in_ios
sha256: "6ec0e13a4c5c646471b9f6a25ceb3ae76d339889d4c0f79b729bf0714215a63e"
url: "https://pub.dev"
source: hosted
version: "5.6.2"
google_sign_in_platform_interface:
dependency: transitive
description:
name: google_sign_in_platform_interface
sha256: e69553c0fc6a76216e9d06a8c3767e291ad9be42171f879aab7ab708569d4393
url: "https://pub.dev"
source: hosted
version: "2.4.1"
google_sign_in_web:
dependency: transitive
description:
name: google_sign_in_web
sha256: "69b9ce0e760945ff52337921a8b5871592b74c92f85e7632293310701eea68cc"
url: "https://pub.dev"
source: hosted
version: "0.12.0+2"
gradiantbutton: gradiantbutton:
dependency: "direct main" dependency: "direct main"
description: description:
@ -904,6 +952,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.7.3" version: "3.7.3"
quiver:
dependency: transitive
description:
name: quiver
sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47
url: "https://pub.dev"
source: hosted
version: "3.2.1"
rxdart: rxdart:
dependency: transitive dependency: transitive
description: description:

@ -75,6 +75,7 @@ dependencies:
timezone: ^0.9.2 timezone: ^0.9.2
firebase_messaging: ^14.6.5 firebase_messaging: ^14.6.5
cached_network_image: ^3.2.3 cached_network_image: ^3.2.3
google_sign_in: ^6.1.4
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save