Skip to content

Commit 3cf9a10

Browse files
committed
user online status
1 parent e31f4fb commit 3cf9a10

File tree

4 files changed

+77
-48
lines changed

4 files changed

+77
-48
lines changed

lib/chatDB.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import 'dart:async';
33

44
import 'package:cloud_firestore/cloud_firestore.dart';
55
import 'package:firebase_auth/firebase_auth.dart';
6-
7-
import 'Models/UserModel.dart';
8-
96
class ChatDBFireStore{
107

118
static String getDocName(){
@@ -36,7 +33,8 @@ class ChatDBFireStore{
3633
'photoUrl': logInUser.photoUrl,
3734
'id': logInUser.uid,
3835
'createdAt': DateTime.now().millisecondsSinceEpoch.toString(),
39-
'chattingWith': null
36+
'chattingWith': null,
37+
'online':null
4038
});
4139
}
4240

@@ -45,4 +43,13 @@ class ChatDBFireStore{
4543
}
4644

4745

46+
static Future<void> makeUserOnline(FirebaseUser logInUser)async{
47+
Firestore.instance
48+
.collection(getDocName())
49+
.document(logInUser.uid)
50+
.updateData({
51+
'isOnline':true
52+
});
53+
}
54+
4855
}

lib/chatData.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class ChatData {
141141

142142
static init(String applicationName, BuildContext context) {
143143
appName = applicationName;
144-
startTime(context);
144+
//startTime(context);
145+
checkUserLogin(context);
145146
}
146147

147148
static checkUserLogin(BuildContext context) async {
@@ -160,7 +161,12 @@ class ChatData {
160161
final FirebaseUser logInUser =
161162
(await firebaseAuth.signInWithCredential(credential)).user;
162163

163-
//return ChatData.userListStack(logInUser.uid, context);
164+
/**
165+
* Make user online
166+
*/
167+
await ChatDBFireStore.makeUserOnline(logInUser);
168+
169+
164170
Navigator.pushReplacement(
165171
context,
166172
MaterialPageRoute(

lib/chatWidget.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ChatWidget {
1616
// List
1717
Container(
1818
child: StreamBuilder(
19-
stream: ChatDBFireStore.streamChatData(),
19+
stream: Firestore.instance.collection(ChatDBFireStore.getDocName()).snapshots(),
2020
builder: (context, snapshot) {
2121
if (!snapshot.hasData) {
2222
return Center(
@@ -52,7 +52,7 @@ class ChatWidget {
5252
children: <Widget>[
5353
Material(
5454
child: document['photoUrl'] != null
55-
? widgetShowImages(document['photoUrl'], 100)
55+
? widgetShowImages(document['photoUrl'], 50)
5656
: Icon(
5757
Icons.account_circle,
5858
size: 50.0,
@@ -73,11 +73,26 @@ class ChatWidget {
7373
alignment: Alignment.centerLeft,
7474
margin: EdgeInsets.fromLTRB(10.0, 0.0, 0.0, 5.0),
7575
),
76+
77+
7678
],
7779
),
7880
margin: EdgeInsets.only(left: 20.0),
7981
),
8082
),
83+
84+
ConstrainedBox(
85+
constraints: new BoxConstraints(
86+
minHeight: 10.0,
87+
minWidth: 10.0,
88+
maxHeight: 30.0,
89+
maxWidth: 30.0,
90+
),
91+
child: new DecoratedBox(
92+
decoration: new BoxDecoration(color:document['isOnline']==true? Colors.greenAccent:Colors.transparent),
93+
),
94+
),
95+
8196
],
8297
),
8398
onPressed: () {

pubspec.yaml

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
name: flutter_chat
2-
description: Chat helper for Flutter android and iOS using firebase as backend services.
3-
4-
version: 0.1.2
5-
homepage: https://github.com/ankesh-kumar/Flutter-chat-sdk
6-
environment:
7-
sdk: ">=2.0.0-dev.68.0 <3.0.0"
8-
9-
dependencies:
10-
flutter:
11-
sdk: flutter
12-
13-
# The following adds the Cupertino Icons font to your application.
14-
# Use with the CupertinoIcons class for iOS style icons.
15-
cupertino_icons: ^0.1.2
16-
firebase_core: ^0.4.3+1
17-
firebase_auth: ^0.15.3
18-
firebase_analytics: ^5.0.9
19-
firebase_storage: ^3.1.0
20-
firebase_messaging: ^6.0.9
21-
cloud_firestore: ^0.13.0+1
22-
fluttertoast: ^3.1.0
23-
image_picker: ^0.6.2+3
24-
photo_view: ^0.9.0
25-
google_sign_in: ^4.0.4
26-
flutter_native_image: ^0.0.4
27-
cached_network_image: ^2.0.0-rc
28-
flutter_dialogflow: ^0.1.3
29-
intl: ^0.16.0
30-
31-
dev_dependencies:
32-
flutter_test:
33-
sdk: flutter
34-
35-
flutter:
36-
uses-material-design: true
37-
38-
assets:
39-
- images/
40-
1+
name: flutter_chat
2+
description: Chat helper for Flutter android and iOS using firebase as backend services.
3+
4+
version: 0.1.2
5+
homepage: https://github.com/ankesh-kumar/Flutter-chat-sdk
6+
environment:
7+
sdk: ">=2.0.0-dev.68.0 <3.0.0"
8+
9+
dependencies:
10+
flutter:
11+
sdk: flutter
12+
13+
# The following adds the Cupertino Icons font to your application.
14+
# Use with the CupertinoIcons class for iOS style icons.
15+
cupertino_icons: ^0.1.2
16+
firebase_core: ^0.4.3+1
17+
firebase_auth: ^0.15.3
18+
firebase_analytics: ^5.0.9
19+
firebase_storage: ^3.1.0
20+
firebase_messaging: ^6.0.9
21+
cloud_firestore: ^0.13.0+1
22+
fluttertoast: ^3.1.0
23+
image_picker: ^0.6.2+3
24+
photo_view: ^0.9.0
25+
google_sign_in: ^4.0.4
26+
flutter_native_image: ^0.0.4
27+
cached_network_image: ^2.0.0-rc
28+
flutter_dialogflow: ^0.1.3
29+
intl: ^0.16.0
30+
firebase_database: ^3.1.1
31+
32+
dev_dependencies:
33+
flutter_test:
34+
sdk: flutter
35+
36+
flutter:
37+
uses-material-design: true
38+
39+
assets:
40+
- images/
41+

0 commit comments

Comments
 (0)