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
logged | |
? Text( | |
'The user is logged!', | |
style: TextStyle( | |
color: Colors.blue, | |
), | |
) | |
: Text( | |
'The user is not logged!', | |
style: TextStyle( |
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
logged ? RaisedButton( | |
child: Text('Logout'), | |
color: Colors.red[300], | |
onPressed: () async { | |
try { | |
await _auth.signOut(); | |
setState(() { | |
logged = false; | |
}); | |
} catch (e) { |
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
logged ? Container() : RaisedButton( | |
child: Text('Login'), | |
color: Colors.blue[300], | |
onPressed: () async { | |
try { | |
_user = await _auth.signInWithEmailAndPassword( | |
email: '[email protected]', | |
password: 'password', | |
); | |
setState(() { |
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
@override | |
void initState() { | |
super.initState(); | |
_auth.currentUser().then((response) { | |
print(response.uid); | |
if (response.uid != null) { | |
setState(() { | |
logged = true; | |
}); | |
} |
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
class _MyHomePageState extends State<MyHomePage> { | |
bool logged = false; | |
FirebaseUser user; | |
final FirebaseAuth _auth = FirebaseAuth.instance; | |
[...] | |
} |
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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( |
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'; | |
class ViewB extends StatelessWidget { | |
final String message; | |
ViewB({Key key, this.message}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { |
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
child: RaisedButton( | |
onPressed: () => Navigator.pushNamed(context, '/view_b', arguments: { | |
'message': 'Hello User 😄', | |
}), | |
color: Colors.green, | |
child: Text( | |
'Goto View B', | |
style: TextStyle( | |
color: Colors.white, | |
), |
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'; | |
class ViewB extends StatelessWidget { | |
final String message; | |
ViewB({Key key, this.message}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { |
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
onPressed: () => Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => ViewB( | |
message: 'Hello User :)', | |
), | |
), | |
), |