Created
August 2, 2020 03:05
-
-
Save mambodin/ca366057372cc79580e073024b1eb8d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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