Created
December 6, 2019 23:34
-
-
Save deadsoul44/f95c72c3d7a3529d4ac2efce751a3866 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 'package:flutter/material.dart'; | |
import 'package:auth/auth.dart'; | |
import 'package:google_sign_in/google_sign_in.dart'; | |
class LoginPage extends StatefulWidget { | |
LoginPage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_LoginPageState createState() => _LoginPageState(); | |
} | |
class _LoginPageState extends State<LoginPage> { | |
GoogleSignIn _vanillaGoogleSignIn = GoogleSignIn( | |
scopes: [ | |
'email', | |
'https://www.googleapis.com/auth/contacts.readonly', | |
], | |
); | |
Future<void> _handleVanillaGoogleSignIn() async { | |
try { | |
await _vanillaGoogleSignIn.signIn(); | |
print(_vanillaGoogleSignIn.currentUser); | |
} catch (error) { | |
print(error); | |
} | |
} | |
Auth auth; | |
bool loggedIn = false; | |
String errorMessage = ""; | |
bool test = false; | |
@override | |
void initState() { | |
super.initState(); | |
auth = Auth.init( | |
scopes: [ | |
'email', | |
'https://www.googleapis.com/auth/contacts.readonly', | |
], | |
/* | |
listener: (user) { | |
loggedIn = user != null; | |
errorMessage = auth.message; | |
setState(() {}); | |
}, | |
*/ | |
); | |
/* | |
auth.signInSilently( | |
listen: (account) { | |
loggedIn = account != null; | |
errorMessage = auth.message; | |
setState(() {}); | |
}, | |
listener: (user) { | |
final test = user != null; | |
print(test); | |
}, | |
); | |
*/ | |
auth.isLoggedIn().then((isIn) { | |
loggedIn = isIn; | |
}); | |
} | |
@override | |
void dispose() { | |
// Important to dispose of the Auth's resources. | |
auth.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
const double _fontSize = 20.0; | |
var screenSize = MediaQuery.of(context).size; | |
var screenHeight = screenSize.height; | |
return Scaffold( | |
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0), | |
appBar: AppBar( | |
elevation: 0.1, | |
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0), | |
title: Text('Welcome to Score AI'), | |
), | |
body: SafeArea( | |
top: false, | |
bottom: false, | |
child: SingleChildScrollView( | |
padding: EdgeInsets.all(50.0), | |
child: Theme( | |
data: ThemeData( | |
brightness: Brightness.dark, | |
inputDecorationTheme: InputDecorationTheme( | |
// hintStyle: new TextStyle(color: Colors.blue, fontSize: 20.0), | |
labelStyle: TextStyle(color: Colors.tealAccent, fontSize: 25.0), | |
), | |
), | |
isMaterialAppTheme: true, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
// Sized box | |
SizedBox(height: screenHeight / 4), | |
// Sign up with Facebook | |
FlatButton( | |
padding: EdgeInsets.only(left: 20), | |
color: Color.fromRGBO(252, 252, 252, 1), | |
child: Row( | |
children: <Widget>[ | |
Image.asset( | |
"images/facebook_logo.png", | |
width: (_fontSize * 1.618), | |
alignment: Alignment.centerLeft, | |
), | |
Padding( | |
padding: const EdgeInsets.all(10.0), | |
child: Text( | |
"Continue with Facebook", | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: _fontSize, | |
color: Color.fromRGBO(58, 66, 86, 1.0), | |
), | |
), | |
), | |
], | |
), | |
onPressed: () { | |
auth.signInWithFacebook().then((value) { | |
if (value) { | |
Navigator.pushReplacementNamed( | |
context, 'datatablespage'); | |
} | |
}).catchError((error) => print(error)); | |
}, | |
), | |
// Sized box | |
const SizedBox(height: _fontSize * 2), | |
// Sign up with Google | |
FlatButton( | |
padding: EdgeInsets.only(left: 20), | |
color: Color.fromRGBO(252, 252, 252, 1), | |
child: Row( | |
children: <Widget>[ | |
Image.asset( | |
"images/google_logo.png", | |
width: (_fontSize * 1.618), | |
alignment: Alignment.centerLeft, | |
), | |
Padding( | |
padding: const EdgeInsets.all(10.0), | |
child: Text( | |
"Continue with Google", | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: _fontSize, | |
color: Color.fromRGBO(58, 66, 86, 1.0), | |
), | |
), | |
), | |
], | |
), | |
onPressed: () { | |
auth.signInWithGoogle().then((value) { | |
if (value) { | |
print("google signin successfull..."); | |
print(value); | |
Navigator.pushReplacementNamed( | |
context, 'datatablespage'); | |
print(auth.signInProvider); | |
} | |
}).catchError((error) => print(error)); | |
print(auth.message); | |
}, | |
), | |
// Sized box | |
const SizedBox(height: _fontSize * 2), | |
// Sign up with Google | |
FlatButton( | |
padding: EdgeInsets.only(left: 20), | |
color: Color.fromRGBO(252, 252, 252, 1), | |
child: Row( | |
children: <Widget>[ | |
Image.asset( | |
"images/google_logo.png", | |
width: (_fontSize * 1.618), | |
alignment: Alignment.centerLeft, | |
), | |
Padding( | |
padding: const EdgeInsets.all(10.0), | |
child: Text( | |
"Vanilla Google", | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: _fontSize, | |
color: Color.fromRGBO(58, 66, 86, 1.0), | |
), | |
), | |
), | |
], | |
), | |
onPressed: _handleVanillaGoogleSignIn, | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment