Last active
May 18, 2020 21:29
-
-
Save braulio94/2449c8453f960e5ef419ec2bcf1029e0 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
Future<Null> _handleSignIn() async { | |
print("handleSignIn"); | |
try { | |
GoogleSignInAccount googleUser = await _googleSignIn.signIn(); | |
GoogleSignInAuthentication googleAuth = await googleUser.authentication; | |
await _auth.signInWithGoogle( | |
accessToken: googleAuth.accessToken, | |
idToken: googleAuth.idToken, | |
); | |
} catch (error) { | |
print(error); | |
} | |
} | |
******************************************************************************************* | |
class MyApp extends StatelessWidget { | |
// Widget home = new MyHomePage(title: 'Gymie'); | |
Future<FirebaseUser> _checkUser () async { | |
final FirebaseUser currentUser = await auth.currentUser(); | |
// if (currentUser != null) home = new ChatHome(); | |
return currentUser; | |
} | |
@override | |
Widget build (BuildContext context) { | |
Widget home = new MyHomePage(title: 'Gymie'); | |
_checkUser().then((FirebaseUser user) { | |
home = new ChatHome(); | |
} | |
); | |
// _checkUser(); | |
return new MaterialApp( | |
title: 'Gymie', | |
home: home, | |
routes: <String, WidgetBuilder> { | |
'/login': (BuildContext context) => new Login(), | |
'/signup': (BuildContext context) => new Signup(), | |
'/chat' : (BuildContext context) => new ChatHome() | |
} | |
); | |
} | |
} | |
************************************************************************************************************ | |
************************************************************************************************************ | |
void main() { | |
runApp(new MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: new MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => new _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counter = 0; | |
@override | |
initState() { | |
super.initState(); | |
mostraUID(); | |
} | |
Future<Null> mostraUID() async { | |
print("Entrei na mostraUID"); | |
GoogleSignInAccount user = googleSignIn.currentUser; | |
if(user == null) | |
user = await googleSignIn.signInSilently(); | |
if(user == null) { | |
user = await googleSignIn.signIn(); | |
} | |
// O gerenciamento de TOKEN é implícito | |
if(await auth.currentUser() == null) { | |
GoogleSignInAuthentication credentials = await googleSignIn.currentUser.authentication; | |
await auth.signInWithGoogle( | |
idToken: credentials.idToken, | |
accessToken: credentials.accessToken, | |
); | |
} | |
_loggedUser = user.email; | |
FirebaseUser userFirebase = await FirebaseAuth.instance.currentUser(); | |
print("User no Firebase: " + userFirebase.uid); | |
print("User no GoogleSignIn: " + user.email); | |
} | |
void _incrementCounter() { | |
setState(() { | |
_counter++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
print("Entrei no Widget build(Build Context context)"); | |
setState(() { | |
_loggedUserTitle = _loggedUser; | |
}); | |
return new Scaffold( | |
appBar: new AppBar( | |
//title: new Text(widget.title), | |
// *************************************************************************************************** // | |
// I'll use "message/$_loggedUser" to compose my database reference (Firebase) to show user's messages | |
title: new Text(_loggedUserTitle), | |
// *************************************************************************************************** // | |
), | |
body: new Center( | |
child: new Text( | |
'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.', | |
), | |
), | |
floatingActionButton: new FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: new Icon(Icons.add), | |
), // This trailing comma makes auto-formatting nicer for build methods. | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment