Skip to content

Commit

Permalink
Merge pull request #7 from 90lucasgabriel/07-messages-list
Browse files Browse the repository at this point in the history
07 - New: List messages;
  • Loading branch information
90lucasgabriel authored Apr 18, 2021
2 parents da56f8f + 4a609d1 commit 5d4aea8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 26 additions & 1 deletion lib/ui/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,32 @@ class _ChatScreenState extends State<ChatScreen> {
body: Column(
children: [
Expanded(
child: Container(),
child: StreamBuilder<QuerySnapshot>(
stream:
FirebaseFirestore.instance.collection('messages').snapshots(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(),
);
default:
List<DocumentSnapshot> documentList =
snapshot.data.docs.reversed.toList();

return ListView.builder(
itemCount: documentList.length,
reverse: true,
itemBuilder: (context, index) {
return ListTile(
title: Text(documentList[index].data()['value']),
);
},
);
}
},
),
),
Input(_sendMessage),
],
Expand Down
8 changes: 2 additions & 6 deletions lib/widgets/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import 'dart:io';
import 'package:image_picker/image_picker.dart';

class Input extends StatefulWidget {
/**
* Send message to Firebase
*/
/// Send message to Firebase
final Function({String value, File file}) sendMessage;

/**
* Constructor
*/
/// Constructor
Input(this.sendMessage);

@override
Expand Down

0 comments on commit 5d4aea8

Please sign in to comment.