Skip to content

Instantly share code, notes, and snippets.

@mambodin
Created August 2, 2020 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mambodin/ca366057372cc79580e073024b1eb8d2 to your computer and use it in GitHub Desktop.
Save mambodin/ca366057372cc79580e073024b1eb8d2 to your computer and use it in GitHub Desktop.
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