Skip to content

Commit d2e4624

Browse files
committed
dependencies upgrade
1 parent a980dde commit d2e4624

File tree

9 files changed

+237
-132
lines changed

9 files changed

+237
-132
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## version 0.1.0 flutter Chat android and iOS
2-
## version 0.1.1 add screen widgets
3-
## version 0.1.2 example added
4-
## version 0.1.3 widget seprated
1+
## version 0.1.4 dependencies upgrade
2+
## version 0.1.3 widget seprated
3+
## version 0.1.2 example added
4+
## version 0.1.1 add screen widgets
5+
## version 0.1.0 flutter Chat android and iOS
6+

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ dependencies:<br/>[flutter_chat](https://pub.dev/packages/flutter_chat)
3737
# Support Development
3838
If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of ☕️
3939

40-
[Be Sponsor](https://github.com/sponsors/ankesh-kumar)<br/>
41-
[![Sponsor](https://1.bp.blogspot.com/-td3V-ijA4Q8/Xr57GVxCyEI/AAAAAAAAORQ/3u78fEKyYkk6aGx8yO1SzeN4Wo9_mr46ACK4BGAsYHg/icons8-love-64.png)](https://github.com/sponsors/ankesh-kumar)
42-
4340
[PayPal](https://paypal.me/ankeshkumar01)
4441

42+
# Thanks for coffee:
43+
Eirik Bakken

example/flutter_chat.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
2222
backgroundColor: Colors.white,
2323
body: ChatWidget.widgetWelcomeScreen(context));
2424
}
25-
}
25+
}

lib/chatDB.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ class ChatDBFireStore {
1010
return dbUser;
1111
}
1212

13-
static Future<void> checkUserExists(FirebaseUser logInUser) async {
14-
final QuerySnapshot result = await Firestore.instance
13+
static Future<void> checkUserExists(User logInUser) async {
14+
final QuerySnapshot result = await FirebaseFirestore.instance
1515
.collection(getDocName())
1616
.where('userId', isEqualTo: logInUser.uid)
17-
.getDocuments();
17+
.get();
1818
final List<DocumentSnapshot> documents = result.documents;
1919
if (documents.length == 0) {
2020
// Update data to server if new user
2121
await saveNewUser(logInUser);
2222
}
2323
}
2424

25-
static saveNewUser(FirebaseUser logInUser) {
26-
Firestore.instance
25+
static saveNewUser(User logInUser) {
26+
FirebaseFirestore.instance
2727
.collection(getDocName())
28-
.document(logInUser.uid)
29-
.setData({
28+
.doc(logInUser.uid)
29+
.set({
3030
'nickname': logInUser.displayName,
31-
'photoUrl': logInUser.photoUrl,
31+
'photoUrl': logInUser.photoURL,
3232
'userId': logInUser.uid,
3333
'createdAt': DateTime.now().millisecondsSinceEpoch.toString(),
3434
'chattingWith': null,
@@ -40,7 +40,7 @@ class ChatDBFireStore {
4040
Firestore.instance.collection(ChatDBFireStore.getDocName()).snapshots();
4141
}
4242

43-
static Future<void> makeUserOnline(FirebaseUser logInUser) async {
43+
static Future<void> makeUserOnline(User logInUser) async {
4444
FirebaseDatabase.instance
4545
.reference()
4646
.child("/status/" + logInUser.uid)

lib/chatData.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22
import 'dart:io';
33
import 'package:firebase_auth/firebase_auth.dart';
4+
import 'package:firebase_core/firebase_core.dart';
45
import 'package:flutter/cupertino.dart';
56
import 'package:flutter/material.dart';
67
import 'package:fluttertoast/fluttertoast.dart';
@@ -88,6 +89,7 @@ class ChatData {
8889
}
8990

9091
static Future<Null> handleSignOut(BuildContext context) async {
92+
await Firebase.initializeApp();
9193
final GoogleSignIn googleSignIn = GoogleSignIn();
9294

9395
await FirebaseAuth.instance.signOut();
@@ -96,23 +98,26 @@ class ChatData {
9698
}
9799

98100
static Future<bool> authUsersGoogle() async {
101+
102+
103+
await Firebase.initializeApp();
99104
final GoogleSignIn googleSignIn = GoogleSignIn();
100105
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
101106

107+
102108
GoogleSignInAccount googleUser = await googleSignIn.signIn();
103109
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
104110

105-
final AuthCredential credential = GoogleAuthProvider.getCredential(
111+
final AuthCredential credential = GoogleAuthProvider.credential(
106112
accessToken: googleAuth.accessToken,
107113
idToken: googleAuth.idToken,
108114
);
109115

110-
final FirebaseUser logInUser =
111-
(await firebaseAuth.signInWithCredential(credential)).user;
116+
final UserCredential logInUser = await firebaseAuth.signInWithCredential(credential);
112117

113118
if (logInUser != null) {
114119
// Check is already sign up
115-
await ChatDBFireStore.checkUserExists(logInUser);
120+
await ChatDBFireStore.checkUserExists(firebaseAuth.currentUser);
116121
return true;
117122
} else {
118123
return false;
@@ -144,19 +149,20 @@ class ChatData {
144149
}
145150

146151
static checkUserLogin(BuildContext context) async {
152+
await Firebase.initializeApp();
147153
final GoogleSignIn googleSignIn = GoogleSignIn();
148154
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
149155

150156
if (await isSignedIn() == true) {
151157
GoogleSignInAccount googleUser = await googleSignIn.signIn();
152158
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
153159

154-
final AuthCredential credential = GoogleAuthProvider.getCredential(
160+
final AuthCredential credential = GoogleAuthProvider.credential(
155161
accessToken: googleAuth.accessToken,
156162
idToken: googleAuth.idToken,
157163
);
158164

159-
final FirebaseUser logInUser =
165+
final User logInUser =
160166
(await firebaseAuth.signInWithCredential(credential)).user;
161167

162168
/**
@@ -184,7 +190,7 @@ class ChatData {
184190
static bool isLastMessageLeft(var listMessage, String id, int index) {
185191
if ((index > 0 &&
186192
listMessage != null &&
187-
listMessage[index - 1]['idFrom'] == id) ||
193+
listMessage[index - 1].get('idFrom') == id) ||
188194
index == 0) {
189195
return true;
190196
} else {
@@ -195,7 +201,7 @@ class ChatData {
195201
static bool isLastMessageRight(var listMessage, String id, int index) {
196202
if ((index > 0 &&
197203
listMessage != null &&
198-
listMessage[index - 1]['idFrom'] != id) ||
204+
listMessage[index - 1].get('idFrom') != id) ||
199205
index == 0) {
200206
return true;
201207
} else {

lib/chatWidget.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ class ChatWidget {
4343

4444
static Widget userListbuildItem(
4545
BuildContext context, String currentUserId, DocumentSnapshot document) {
46-
print('firebase ' + document['userId']);
46+
print('firebase ' + document.get('userId'));
4747
print(currentUserId);
48-
if (document['userId'] == currentUserId) {
48+
if (document.get('userId') == currentUserId) {
4949
return Container();
5050
} else {
5151
return Container(
5252
child: FlatButton(
5353
child: Row(
5454
children: <Widget>[
5555
Material(
56-
child: document['photoUrl'] != null
57-
? widgetShowImages(document['photoUrl'], 50)
56+
child: document.get('photoUrl') != null
57+
? widgetShowImages(document.get('photoUrl'), 50)
5858
: Icon(
5959
Icons.account_circle,
6060
size: 50.0,
@@ -69,7 +69,7 @@ class ChatWidget {
6969
children: <Widget>[
7070
Container(
7171
child: Text(
72-
'Nickname: ${document['nickname']}',
72+
'Nickname: ${document.get('nickname')}',
7373
style: TextStyle(color: primaryColor),
7474
),
7575
alignment: Alignment.centerLeft,
@@ -89,7 +89,7 @@ class ChatWidget {
8989
),
9090
child: new DecoratedBox(
9191
decoration: new BoxDecoration(
92-
color: document['online'] == 'online'
92+
color: document.get('online') == 'online'
9393
? Colors.greenAccent
9494
: Colors.transparent),
9595
),
@@ -103,8 +103,8 @@ class ChatWidget {
103103
builder: (context) => Chat(
104104
currentUserId: currentUserId,
105105
peerId: document.documentID,
106-
peerName: document['nickname'],
107-
peerAvatar: document['photoUrl'],
106+
peerName: document.get('nickname'),
107+
peerAvatar: document.get('photoUrl'),
108108
)));
109109
},
110110
color: viewBg,
@@ -193,13 +193,13 @@ class ChatWidget {
193193

194194
static Widget widgetChatBuildItem(BuildContext context, var listMessage,
195195
String id, int index, DocumentSnapshot document, String peerAvatar) {
196-
if (document['idFrom'] == id) {
196+
if (document.get('idFrom') == id) {
197197
return Row(
198198
children: <Widget>[
199-
document['type'] == 0
200-
? chatText(document['content'], id, listMessage, index, true)
199+
document.get('type') == 0
200+
? chatText(document.get('content'), id, listMessage, index, true)
201201
: chatImage(
202-
context, id, listMessage, document['content'], index, true)
202+
context, id, listMessage, document.get('content'), index, true)
203203
],
204204
mainAxisAlignment: MainAxisAlignment.end,
205205
);
@@ -218,10 +218,10 @@ class ChatWidget {
218218
clipBehavior: Clip.hardEdge,
219219
)
220220
: Container(width: 35.0),
221-
document['type'] == 0
221+
document.get('type') == 0
222222
? chatText(
223-
document['content'], id, listMessage, index, false)
224-
: chatImage(context, id, listMessage, document['content'],
223+
document.get('content'), id, listMessage, index, false)
224+
: chatImage(context, id, listMessage, document.get('content'),
225225
index, false)
226226
],
227227
),
@@ -232,7 +232,7 @@ class ChatWidget {
232232
child: Text(
233233
DateFormat('dd MMM kk:mm').format(
234234
DateTime.fromMillisecondsSinceEpoch(
235-
int.parse(document['timestamp']))),
235+
int.parse(document.get('timestamp')))),
236236
style: TextStyle(
237237
color: greyColor,
238238
fontSize: 12.0,
@@ -257,9 +257,9 @@ class ChatWidget {
257257
child: CircularProgressIndicator(
258258
valueColor: AlwaysStoppedAnimation<Color>(themeColor)))
259259
: StreamBuilder(
260-
stream: Firestore.instance
260+
stream: FirebaseFirestore.instance
261261
.collection('messages')
262-
.document(groupChatId)
262+
.doc(groupChatId)
263263
.collection(groupChatId)
264264
.orderBy('timestamp', descending: true)
265265
.limit(20)

lib/screens/chat.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import 'dart:io';
33
import 'package:cloud_firestore/cloud_firestore.dart';
44
import 'package:firebase_storage/firebase_storage.dart';
55
import 'package:flutter/material.dart';
6-
import 'package:flutter_chat/chatWidget.dart';
76
import 'package:flutter_native_image/flutter_native_image.dart';
87
import 'package:fluttertoast/fluttertoast.dart';
98
import 'package:image_picker/image_picker.dart';
9+
import '../chatWidget.dart';
1010
import '../constants.dart';
1111

1212

@@ -159,13 +159,13 @@ class _ChatScreenState extends State<_ChatScreen> {
159159
if (content.trim() != '') {
160160
textEditingController.clear();
161161

162-
var documentReference = Firestore.instance
162+
var documentReference = FirebaseFirestore.instance
163163
.collection('messages')
164-
.document(groupChatId)
164+
.doc(groupChatId)
165165
.collection(groupChatId)
166-
.document(DateTime.now().millisecondsSinceEpoch.toString());
166+
.doc(DateTime.now().millisecondsSinceEpoch.toString());
167167

168-
Firestore.instance.runTransaction((transaction) async {
168+
FirebaseFirestore.instance.runTransaction((transaction) async {
169169
await transaction.set(
170170
documentReference,
171171
{

0 commit comments

Comments
 (0)