add firebase auth in flutter code example
Example 1: how to add data in firebase in flutter
StreamBuilder(
stream: _firebaseRef.onValue,
builder: (context, snap) {
if (snap.hasData && !snap.hasError && snap.data.snapshot.value != null) {
Map data = snap.data.snapshot.value;
List item = [];
data.forEach((index, data) => item.add({"key": index, ...data}));
return ListView.builder(
itemCount: item.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(item[index]['message']),
trailing: Text(DateFormat("hh:mm:ss")
.format(DateTime.fromMicrosecondsSinceEpoch(
item[index]['timestamp'] * 1000))
.toString()),
onTap: () =>
updateTimeStamp(item[index]['key']),
onLongPress: () =>
deleteMessage(item[index]['key']),
);
},
);
}
else
return Text("No data");
},
)
Example 2: sigup and sign out using firebase auth in flutter
Future<Null> _signOut() async {
await _auth.signOut();
this.setState(() {
isLoading = false;
});
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => MyApp()),
(Route<dynamic> route) => false);
}