Skip to content

Commit 4e9df34

Browse files
committed
upgrade version libraries, gradle. Fix rounded image, upload file.
1 parent 63afad3 commit 4e9df34

File tree

9 files changed

+362
-257
lines changed

9 files changed

+362
-257
lines changed

.idea/libraries/Dart_Packages.xml

Lines changed: 136 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Flutter_Plugins.xml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ apply plugin: 'com.android.application'
1515
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
1616

1717
android {
18-
compileSdkVersion 27
18+
compileSdkVersion 28
1919

2020
lintOptions {
2121
disable 'InvalidPackage'
@@ -25,7 +25,7 @@ android {
2525
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
2626
applicationId "com.dfa.flutterchatdemo"
2727
minSdkVersion 21
28-
targetSdkVersion 27
28+
targetSdkVersion 28
2929
versionCode 1
3030
versionName "1.0"
3131
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -61,7 +61,8 @@ dependencies {
6161
testImplementation 'junit:junit:4.12'
6262
androidTestImplementation 'com.android.support.test:runner:1.0.2'
6363
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
64-
compile 'com.google.firebase:firebase-core:16.0.1'
64+
compile 'com.google.firebase:firebase-core:16.0.4'
6565
}
6666

67-
apply plugin: 'com.google.gms.google-services'
67+
apply plugin: 'com.google.gms.google-services'
68+
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

android/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.1.4'
8+
classpath 'com.android.tools.build:gradle:3.2.1'
99
classpath 'com.google.gms:google-services:4.0.0'
1010
}
1111
}
@@ -24,7 +24,16 @@ subprojects {
2424
subprojects {
2525
project.evaluationDependsOn(':app')
2626
}
27-
27+
subprojects {
28+
project.configurations.all {
29+
resolutionStrategy.eachDependency { details ->
30+
if (details.requested.group == 'com.android.support'
31+
&& !details.requested.name.contains('multidex') ) {
32+
details.useVersion "26.1.0"
33+
}
34+
}
35+
}
36+
}
2837
task clean(type: Delete) {
2938
delete rootProject.buildDir
3039
}

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

lib/chat.dart

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Chat extends StatelessWidget {
1515
final String peerId;
1616
final String peerAvatar;
1717

18-
Chat({Key key, @required this.peerId, @required this.peerAvatar}) : super(key: key);
18+
Chat({Key key, @required this.peerId, @required this.peerAvatar})
19+
: super(key: key);
1920

2021
@override
2122
Widget build(BuildContext context) {
@@ -39,10 +40,12 @@ class ChatScreen extends StatefulWidget {
3940
final String peerId;
4041
final String peerAvatar;
4142

42-
ChatScreen({Key key, @required this.peerId, @required this.peerAvatar}) : super(key: key);
43+
ChatScreen({Key key, @required this.peerId, @required this.peerAvatar})
44+
: super(key: key);
4345

4446
@override
45-
State createState() => new ChatScreenState(peerId: peerId, peerAvatar: peerAvatar);
47+
State createState() =>
48+
new ChatScreenState(peerId: peerId, peerAvatar: peerAvatar);
4649
}
4750

4851
class ChatScreenState extends State<ChatScreen> {
@@ -61,7 +64,8 @@ class ChatScreenState extends State<ChatScreen> {
6164
bool isShowSticker;
6265
String imageUrl;
6366

64-
final TextEditingController textEditingController = new TextEditingController();
67+
final TextEditingController textEditingController =
68+
new TextEditingController();
6569
final ScrollController listScrollController = new ScrollController();
6670
final FocusNode focusNode = new FocusNode();
6771

@@ -123,16 +127,15 @@ class ChatScreenState extends State<ChatScreen> {
123127
Future uploadFile() async {
124128
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
125129
StorageReference reference = FirebaseStorage.instance.ref().child(fileName);
126-
StorageUploadTask uploadTask = reference.putFile(imageFile);
127-
128-
Uri downloadUrl = (await uploadTask.future).downloadUrl;
129-
imageUrl = downloadUrl.toString();
130+
reference.putFile(imageFile);
131+
reference.getDownloadURL().then((dynamic value) {
132+
imageUrl = value.toString();
133+
setState(() {
134+
isLoading = false;
135+
});
130136

131-
setState(() {
132-
isLoading = false;
137+
onSendMessage(imageUrl, 1);
133138
});
134-
135-
onSendMessage(imageUrl, 1);
136139
}
137140

138141
void onSendMessage(String content, int type) {
@@ -158,7 +161,8 @@ class ChatScreenState extends State<ChatScreen> {
158161
},
159162
);
160163
});
161-
listScrollController.animateTo(0.0, duration: Duration(milliseconds: 300), curve: Curves.easeOut);
164+
listScrollController.animateTo(0.0,
165+
duration: Duration(milliseconds: 300), curve: Curves.easeOut);
162166
} else {
163167
Fluttertoast.showToast(msg: 'Nothing to send');
164168
}
@@ -178,8 +182,12 @@ class ChatScreenState extends State<ChatScreen> {
178182
),
179183
padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
180184
width: 200.0,
181-
decoration: BoxDecoration(color: greyColor2, borderRadius: BorderRadius.circular(8.0)),
182-
margin: EdgeInsets.only(bottom: isLastMessageRight(index) ? 20.0 : 10.0, right: 10.0),
185+
decoration: BoxDecoration(
186+
color: greyColor2,
187+
borderRadius: BorderRadius.circular(8.0)),
188+
margin: EdgeInsets.only(
189+
bottom: isLastMessageRight(index) ? 20.0 : 10.0,
190+
right: 10.0),
183191
)
184192
: document['type'] == 1
185193
// Image
@@ -188,7 +196,8 @@ class ChatScreenState extends State<ChatScreen> {
188196
child: CachedNetworkImage(
189197
placeholder: Container(
190198
child: CircularProgressIndicator(
191-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
199+
valueColor:
200+
AlwaysStoppedAnimation<Color>(themeColor),
192201
),
193202
width: 200.0,
194203
height: 200.0,
@@ -210,15 +219,19 @@ class ChatScreenState extends State<ChatScreen> {
210219
borderRadius: BorderRadius.all(
211220
Radius.circular(8.0),
212221
),
222+
clipBehavior: Clip.hardEdge,
213223
),
214224
imageUrl: document['content'],
215225
width: 200.0,
216226
height: 200.0,
217227
fit: BoxFit.cover,
218228
),
219229
borderRadius: BorderRadius.all(Radius.circular(8.0)),
230+
clipBehavior: Clip.hardEdge,
220231
),
221-
margin: EdgeInsets.only(bottom: isLastMessageRight(index) ? 20.0 : 10.0, right: 10.0),
232+
margin: EdgeInsets.only(
233+
bottom: isLastMessageRight(index) ? 20.0 : 10.0,
234+
right: 10.0),
222235
)
223236
// Sticker
224237
: Container(
@@ -228,7 +241,9 @@ class ChatScreenState extends State<ChatScreen> {
228241
height: 100.0,
229242
fit: BoxFit.cover,
230243
),
231-
margin: EdgeInsets.only(bottom: isLastMessageRight(index) ? 20.0 : 10.0, right: 10.0),
244+
margin: EdgeInsets.only(
245+
bottom: isLastMessageRight(index) ? 20.0 : 10.0,
246+
right: 10.0),
232247
),
233248
],
234249
mainAxisAlignment: MainAxisAlignment.end,
@@ -246,7 +261,8 @@ class ChatScreenState extends State<ChatScreen> {
246261
placeholder: Container(
247262
child: CircularProgressIndicator(
248263
strokeWidth: 1.0,
249-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
264+
valueColor:
265+
AlwaysStoppedAnimation<Color>(themeColor),
250266
),
251267
width: 35.0,
252268
height: 35.0,
@@ -260,6 +276,7 @@ class ChatScreenState extends State<ChatScreen> {
260276
borderRadius: BorderRadius.all(
261277
Radius.circular(18.0),
262278
),
279+
clipBehavior: Clip.hardEdge,
263280
)
264281
: Container(width: 35.0),
265282
document['type'] == 0
@@ -270,7 +287,9 @@ class ChatScreenState extends State<ChatScreen> {
270287
),
271288
padding: EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
272289
width: 200.0,
273-
decoration: BoxDecoration(color: primaryColor, borderRadius: BorderRadius.circular(8.0)),
290+
decoration: BoxDecoration(
291+
color: primaryColor,
292+
borderRadius: BorderRadius.circular(8.0)),
274293
margin: EdgeInsets.only(left: 10.0),
275294
)
276295
: document['type'] == 1
@@ -279,7 +298,8 @@ class ChatScreenState extends State<ChatScreen> {
279298
child: CachedNetworkImage(
280299
placeholder: Container(
281300
child: CircularProgressIndicator(
282-
valueColor: AlwaysStoppedAnimation<Color>(themeColor),
301+
valueColor: AlwaysStoppedAnimation<Color>(
302+
themeColor),
283303
),
284304
width: 200.0,
285305
height: 200.0,
@@ -301,13 +321,16 @@ class ChatScreenState extends State<ChatScreen> {
301321
borderRadius: BorderRadius.all(
302322
Radius.circular(8.0),
303323
),
324+
clipBehavior: Clip.hardEdge,
304325
),
305326
imageUrl: document['content'],
306327
width: 200.0,
307328
height: 200.0,
308329
fit: BoxFit.cover,
309330
),
310-
borderRadius: BorderRadius.all(Radius.circular(8.0)),
331+
borderRadius:
332+
BorderRadius.all(Radius.circular(8.0)),
333+
clipBehavior: Clip.hardEdge,
311334
),
312335
margin: EdgeInsets.only(left: 10.0),
313336
)
@@ -318,7 +341,9 @@ class ChatScreenState extends State<ChatScreen> {
318341
height: 100.0,
319342
fit: BoxFit.cover,
320343
),
321-
margin: EdgeInsets.only(bottom: isLastMessageRight(index) ? 20.0 : 10.0, right: 10.0),
344+
margin: EdgeInsets.only(
345+
bottom: isLastMessageRight(index) ? 20.0 : 10.0,
346+
right: 10.0),
322347
),
323348
],
324349
),
@@ -327,9 +352,13 @@ class ChatScreenState extends State<ChatScreen> {
327352
isLastMessageLeft(index)
328353
? Container(
329354
child: Text(
330-
DateFormat('dd MMM kk:mm')
331-
.format(DateTime.fromMillisecondsSinceEpoch(int.parse(document['timestamp']))),
332-
style: TextStyle(color: greyColor, fontSize: 12.0, fontStyle: FontStyle.italic),
355+
DateFormat('dd MMM kk:mm').format(
356+
DateTime.fromMillisecondsSinceEpoch(
357+
int.parse(document['timestamp']))),
358+
style: TextStyle(
359+
color: greyColor,
360+
fontSize: 12.0,
361+
fontStyle: FontStyle.italic),
333362
),
334363
margin: EdgeInsets.only(left: 50.0, top: 5.0, bottom: 5.0),
335364
)
@@ -343,15 +372,21 @@ class ChatScreenState extends State<ChatScreen> {
343372
}
344373

345374
bool isLastMessageLeft(int index) {
346-
if ((index > 0 && listMessage != null && listMessage[index - 1]['idFrom'] == id) || index == 0) {
375+
if ((index > 0 &&
376+
listMessage != null &&
377+
listMessage[index - 1]['idFrom'] == id) ||
378+
index == 0) {
347379
return true;
348380
} else {
349381
return false;
350382
}
351383
}
352384

353385
bool isLastMessageRight(int index) {
354-
if ((index > 0 && listMessage != null && listMessage[index - 1]['idFrom'] != id) || index == 0) {
386+
if ((index > 0 &&
387+
listMessage != null &&
388+
listMessage[index - 1]['idFrom'] != id) ||
389+
index == 0) {
355390
return true;
356391
} else {
357392
return false;
@@ -500,7 +535,9 @@ class ChatScreenState extends State<ChatScreen> {
500535
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
501536
),
502537
decoration: new BoxDecoration(
503-
border: new Border(top: new BorderSide(color: greyColor2, width: 0.5)), color: Colors.white),
538+
border:
539+
new Border(top: new BorderSide(color: greyColor2, width: 0.5)),
540+
color: Colors.white),
504541
padding: EdgeInsets.all(5.0),
505542
height: 180.0,
506543
);
@@ -511,7 +548,8 @@ class ChatScreenState extends State<ChatScreen> {
511548
child: isLoading
512549
? Container(
513550
child: Center(
514-
child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(themeColor)),
551+
child: CircularProgressIndicator(
552+
valueColor: AlwaysStoppedAnimation<Color>(themeColor)),
515553
),
516554
color: Colors.white.withOpacity(0.8),
517555
)
@@ -579,14 +617,18 @@ class ChatScreenState extends State<ChatScreen> {
579617
width: double.infinity,
580618
height: 50.0,
581619
decoration: new BoxDecoration(
582-
border: new Border(top: new BorderSide(color: greyColor2, width: 0.5)), color: Colors.white),
620+
border:
621+
new Border(top: new BorderSide(color: greyColor2, width: 0.5)),
622+
color: Colors.white),
583623
);
584624
}
585625

586626
Widget buildListMessage() {
587627
return Flexible(
588628
child: groupChatId == ''
589-
? Center(child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(themeColor)))
629+
? Center(
630+
child: CircularProgressIndicator(
631+
valueColor: AlwaysStoppedAnimation<Color>(themeColor)))
590632
: StreamBuilder(
591633
stream: Firestore.instance
592634
.collection('messages')
@@ -598,12 +640,15 @@ class ChatScreenState extends State<ChatScreen> {
598640
builder: (context, snapshot) {
599641
if (!snapshot.hasData) {
600642
return Center(
601-
child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(themeColor)));
643+
child: CircularProgressIndicator(
644+
valueColor:
645+
AlwaysStoppedAnimation<Color>(themeColor)));
602646
} else {
603647
listMessage = snapshot.data.documents;
604648
return ListView.builder(
605649
padding: EdgeInsets.all(10.0),
606-
itemBuilder: (context, index) => buildItem(index, snapshot.data.documents[index]),
650+
itemBuilder: (context, index) =>
651+
buildItem(index, snapshot.data.documents[index]),
607652
itemCount: snapshot.data.documents.length,
608653
reverse: true,
609654
controller: listScrollController,

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class MainScreenState extends State<MainScreen> {
143143
fit: BoxFit.cover,
144144
),
145145
borderRadius: BorderRadius.all(Radius.circular(25.0)),
146+
clipBehavior: Clip.hardEdge,
146147
),
147148
new Flexible(
148149
child: Container(

0 commit comments

Comments
 (0)