-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_screen.dart
123 lines (111 loc) · 3.61 KB
/
chat_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'package:flutter/material.dart';
import 'package:heyther/views/conversation_screen.dart';
//import 'package:cloud_firestore/cloud_firestore.dart';
//import 'package:heyther/widgets/chat_widget.dart';
import 'package:heyther/widgets/header_widget.dart';
import 'package:heyther/views/home.dart';
import 'package:heyther/views/search_page.dart';
import 'package:heyther/services/Database.dart';
//import 'package:timeago/timeago.dart' as tAgo;
//import 'package:heyther/widgets/posts_widget.dart';
class ChatRoom extends StatefulWidget{
@override
_ChatRoomState createState() => _ChatRoomState();
}
class _ChatRoomState extends State<ChatRoom>{
DatabaseMethods databaseMethods= new DatabaseMethods();
Stream chatRoomsStream;
Widget chatroomList(){
return StreamBuilder(
stream: chatRoomsStream,
builder: (context,snapshot){
return snapshot.hasData ? ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context,index){
//print(snapshot.data.docs[index].data()["chatroomID"]);
return ChatTile(
snapshot.data.docs[index].data()["chatroomID"].toString().replaceAll("_${currentUser.username}", "")
.replaceAll("${currentUser.username}_",""),
snapshot.data.docs[index].data()["chatroomID"].toString()
);
}
):
Container();
}
);
}
@override
void initState(){
databaseMethods.getChatrooms(currentUser.username).then((value){
setState((){
chatRoomsStream=value;
});
});
super.initState();
}
displaySearchPage() {
Navigator.push(context, MaterialPageRoute(builder: (context)=>SearchPage()
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: header(context, strTitle: "Chats", isAppTitle: false),
body: Container(
color:Colors.grey,
child:chatroomList()
),
floatingActionButton: Padding(
padding: const EdgeInsets.only(bottom: 50),
child:
FloatingActionButton(
heroTag: "btn1",
child: Icon(Icons.search),
onPressed: ()=>displaySearchPage()
/*{
Navigator.push(context, MaterialPageRoute(
builder: (context)=> ChatSearchPage()
));
}*/,
),
)
);
}
}
class ChatTile extends StatelessWidget{
final String username;
final String chatroomid;
ChatTile(this.username, this.chatroomid);
@override
Widget build(BuildContext context){
return GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(
builder: (context)=> ConversationScreen(chatroomid, username)
));
},
child: Container(
margin: EdgeInsets.symmetric(vertical:1),
padding: EdgeInsets.symmetric(horizontal:24, vertical:16 ),
color: Colors.black26,
child: Row(
children:[
Container(
alignment: Alignment.center,
height: 40,
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(40)
),
child:
Text("${username.substring(0,1).toUpperCase()}", style:TextStyle(color:Colors.white))
),
SizedBox(width: 8),
Text(username, style: TextStyle(color: Colors.white, fontSize: 16))
]
)
)
);
}
}