Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: Firestore.instance
.collection('/ChatApp/PuC0dvcVj5P6i1B9Qmns/messages/')
.snapshots(),
builder: (ctx, streamSnapshot) {
print(streamSnapshot.data.documents);
final documents = streamSnapshot.data.documents;
return ListView.builder(
itemBuilder: (ctx, index) =>
Container(child: Text('CHAT!'), padding: EdgeInsets.all(8)),
itemCount: documents.length,
);
}),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Firestore.instance
.collection('/ChatApp/PuC0dvcVj5P6i1B9Qmns/messages')
.snapshots()
.listen((data) {
data.documents.forEach((element) {
print(element['chat']);
});
});
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.