-
-
Save MeshkaniMohammad/7367151a3dd2a31969e7a57ff88f86a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:firebase_auth/firebase_auth.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
class FBApi { | |
static FirebaseAuth _auth = FirebaseAuth.instance; | |
static GoogleSignIn _googleSignIn = GoogleSignIn(); | |
FirebaseUser firebaseUser; | |
FBApi(FirebaseUser user) { | |
this.firebaseUser = user; | |
} | |
static Future<FBApi> signInWithGoogle() async { | |
final GoogleSignInAccount googleUser = await _googleSignIn.signIn(); | |
final GoogleSignInAuthentication googleAuth = | |
await googleUser.authentication; | |
try { | |
final FirebaseUser user = await _auth.signInWithGoogle( | |
accessToken: googleAuth.accessToken, | |
idToken: googleAuth.idToken, | |
); | |
assert(user.email != null); | |
assert(user.displayName != null); | |
assert(await user.getIdToken() != null); | |
final FirebaseUser currentUser = await _auth.currentUser(); | |
assert(user.uid == currentUser.uid); | |
return FBApi(user); | |
} catch (error, stack) { | |
print("Could not sign in with Google, here is the error $error"); | |
FlutterErrorDetails(exception: FlutterError(error), stack: stack); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:ui' show ImageFilter; | |
import 'package:firebase_example/Model/Api.dart'; | |
import 'package:firebase_example/Ui/home.dart'; | |
import 'package:flutter/material.dart'; | |
class LoginPage extends StatefulWidget { | |
@override | |
LoginPageState createState() { | |
return new LoginPageState(); | |
} | |
} | |
class LoginPageState extends State<LoginPage> { | |
String _status; | |
Future<bool> _loginUser() async { | |
final api = await FBApi.signInWithGoogle(); | |
if (api != null) { | |
setState(() { | |
_status = 'Signed in with google'; | |
}); | |
return true; | |
} else { | |
print("fuuuuuuuuck"); | |
return false; | |
} | |
} | |
@override | |
void initState() { | |
_status = 'Not Authenticated'; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
centerTitle: true, | |
title: Text('Sign In'), | |
), | |
body: Center( | |
child: Stack( | |
children: <Widget>[ | |
Center( | |
child: ConstrainedBox( | |
constraints: BoxConstraints.expand( | |
width: 250.0, | |
height: 250.0, | |
), | |
child: Container( | |
color: Colors.cyan[100].withOpacity(0.7), | |
), | |
), | |
), | |
Center( | |
child: BackdropFilter( | |
filter: ImageFilter.blur( | |
sigmaX: 5.0, | |
sigmaY: 5.0, | |
), | |
child: Container( | |
width: 250.0, | |
height: 250.0, | |
color: Colors.grey[100].withOpacity(0.2), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: <Widget>[ | |
Text( | |
"Login to the App!", | |
style: TextStyle( | |
color: Colors.black54, | |
fontSize: 30.0, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
FlatButton( | |
color: Colors.black54, | |
onPressed: () async { | |
bool b = await _loginUser(); | |
b | |
? debugPrint("loged in with google") //Navigator.of(context).pushNamed('home-page') | |
: debugPrint("login fucked"); | |
/*Scaffold.of(context).showSnackBar( | |
SnackBar( | |
content: Text('Wrong Email!'), | |
), | |
);*/ | |
}, | |
textColor: Colors.white.withOpacity(0.5), | |
child: Text('Sign In!'), | |
) | |
], | |
), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:ui' show ImageFilter; | |
import 'package:firebase_example/Model/Api.dart'; | |
import 'package:firebase_example/Ui/home.dart'; | |
import 'package:flutter/material.dart'; | |
class LoginPage extends StatefulWidget { | |
@override | |
LoginPageState createState() { | |
return new LoginPageState(); | |
} | |
} | |
class LoginPageState extends State<LoginPage> { | |
String _status; | |
Future<bool> _loginUser() async { | |
final api = await FBApi.signInWithGoogle(); | |
if (api != null) { | |
setState(() { | |
_status = 'Signed in with google'; | |
}); | |
return true; | |
} else { | |
print("fuuuuuuuuck"); | |
return false; | |
} | |
} | |
@override | |
void initState() { | |
_status = 'Not Authenticated'; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
centerTitle: true, | |
title: Text('Sign In'), | |
), | |
body: Center( | |
child: Stack( | |
children: <Widget>[ | |
Center( | |
child: ConstrainedBox( | |
constraints: BoxConstraints.expand( | |
width: 250.0, | |
height: 250.0, | |
), | |
child: Container( | |
color: Colors.cyan[100].withOpacity(0.7), | |
), | |
), | |
), | |
Center( | |
child: BackdropFilter( | |
filter: ImageFilter.blur( | |
sigmaX: 5.0, | |
sigmaY: 5.0, | |
), | |
child: Container( | |
width: 250.0, | |
height: 250.0, | |
color: Colors.grey[100].withOpacity(0.2), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: <Widget>[ | |
Text( | |
"Login to the App!", | |
style: TextStyle( | |
color: Colors.black54, | |
fontSize: 30.0, | |
fontWeight: FontWeight.w600, | |
), | |
), | |
FlatButton( | |
color: Colors.black54, | |
onPressed: () async { | |
bool b = await _loginUser(); | |
b | |
? debugPrint("loged in with google") //Navigator.of(context).pushNamed('home-page') | |
: debugPrint("login fucked"); | |
/*Scaffold.of(context).showSnackBar( | |
SnackBar( | |
content: Text('Wrong Email!'), | |
), | |
);*/ | |
}, | |
textColor: Colors.white.withOpacity(0.5), | |
child: Text('Sign In!'), | |
) | |
], | |
), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:3.0.1' | |
classpath 'com.google.gms:google-services:4.0.0' | |
} | |
} | |
allprojects { | |
repositories { | |
maven { | |
url "https://maven.google.com" | |
} | |
google() | |
jcenter() | |
} | |
} | |
rootProject.buildDir = '../build' | |
subprojects { | |
project.buildDir = "${rootProject.buildDir}/${project.name}" | |
} | |
subprojects { | |
project.evaluationDependsOn(':app') | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} | |
subprojects { | |
project.configurations.all { | |
resolutionStrategy.eachDependency { details -> | |
if (details.requested.group == 'com.android.support' | |
&& !details.requested.name.contains('multidex') ) { | |
details.useVersion "27.1.0" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment