From f2cf8db1360a9edb006de00394a73c45ede7d819 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Tue, 26 Feb 2019 20:48:21 -0600 Subject: [PATCH] Testing app --- lib/src/App.dart | 17 +---------- .../resources/google_sign_in_provider.dart | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 lib/src/resources/google_sign_in_provider.dart diff --git a/lib/src/App.dart b/lib/src/App.dart index 95c7509..68c3ba6 100644 --- a/lib/src/App.dart +++ b/lib/src/App.dart @@ -6,21 +6,6 @@ import './models/user_model.dart'; import './resources/firestore_provider.dart'; class App extends StatelessWidget { - Widget build(BuildContext context) { - return MaterialApp( - title: 'Do more', - //home: Text('Start'), - home: Scaffold( - appBar: AppBar( - title: Text('DO>'), - ), - body: Text('Tasks'), - ), - ); - } -} - -/* class App extends StatelessWidget { Widget build(BuildContext context) { final fire = FirestoreProvider(); return MaterialApp( @@ -86,4 +71,4 @@ class App extends StatelessWidget { ), ); } -} */ +} diff --git a/lib/src/resources/google_sign_in_provider.dart b/lib/src/resources/google_sign_in_provider.dart new file mode 100644 index 0000000..0e3525f --- /dev/null +++ b/lib/src/resources/google_sign_in_provider.dart @@ -0,0 +1,28 @@ +import 'dart:async'; + +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:google_sign_in/google_sign_in.dart'; + +class GoogleSignInProvider { + final GoogleSignIn _googleSignIn; + final FirebaseAuth _auth; + + GoogleSignInProvider([GoogleSignIn googleSignIn, FirebaseAuth firebaseAuth]) + : _googleSignIn = googleSignIn ?? GoogleSignIn(), + _auth = firebaseAuth ?? FirebaseAuth.instance; + + Future signIn() async { + final GoogleSignInAccount googleUser = await _googleSignIn.signIn(); + final GoogleSignInAuthentication googleAuth = + await googleUser.authentication; + + final AuthCredential credential = GoogleAuthProvider.getCredential( + accessToken: googleAuth.accessToken, + idToken: googleAuth.idToken, + ); + + final FirebaseUser user = await _auth.signInWithCredential(credential); + print("signed in " + user.displayName); + return user; + } +}