Skip to content

Instantly share code, notes, and snippets.

View timbergus's full-sized avatar

Gustavo Muñoz timbergus

View GitHub Profile
logged
? Text(
'The user is logged!',
style: TextStyle(
color: Colors.blue,
),
)
: Text(
'The user is not logged!',
style: TextStyle(
logged ? RaisedButton(
child: Text('Logout'),
color: Colors.red[300],
onPressed: () async {
try {
await _auth.signOut();
setState(() {
logged = false;
});
} catch (e) {
logged ? Container() : RaisedButton(
child: Text('Login'),
color: Colors.blue[300],
onPressed: () async {
try {
_user = await _auth.signInWithEmailAndPassword(
email: '[email protected]',
password: 'password',
);
setState(() {
@override
void initState() {
super.initState();
_auth.currentUser().then((response) {
print(response.uid);
if (response.uid != null) {
setState(() {
logged = true;
});
}
class _MyHomePageState extends State<MyHomePage> {
bool logged = false;
FirebaseUser user;
final FirebaseAuth _auth = FirebaseAuth.instance;
[...]
}
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(
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) {
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,
),
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) {
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ViewB(
message: 'Hello User :)',
),
),
),