Skip to content

Instantly share code, notes, and snippets.

@timbergus
Created June 23, 2019 21:25
Show Gist options
  • Save timbergus/a6b20004e662c8015e1a0cf24c99dfd3 to your computer and use it in GitHub Desktop.
Save timbergus/a6b20004e662c8015e1a0cf24c99dfd3 to your computer and use it in GitHub Desktop.
// Logged status.
bool isLogged = false;
// Firebase authentication instance.
FirebaseAuth _auth = FirebaseAuth.instance;
// The init state will check the logged status of the user.
@override
void initState() {
super.initState();
_auth.currentUser().then((response) {
if (response != null) {
setState(() {
isLogged = true;
});
}
});
}
// The login button will login to the app using
// the user credentials, and sets the logged status
// to true.
RaisedButton(
child: Text(
'Login',
),
color: Colors.blue[400],
onPressed: () async {
await _auth.signInWithEmailAndPassword(
email: 'user@fakemailaddress.com',
password: 'password',
);
setState(() {
isLogged = true;
});
}
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment