1
1
import 'dart:async' ;
2
2
3
3
import 'package:file_picker/file_picker.dart' ;
4
+ import 'package:flutter/cupertino.dart' ;
4
5
import 'package:flutter/material.dart' ;
5
6
import 'package:flutter_chat_ui/flutter_chat_ui.dart' ;
6
7
import 'package:flutter_mqtt/abstraction/models/ChatMessage.dart' ;
@@ -12,6 +13,7 @@ import 'package:flutter_mqtt/global/ChatApp.dart';
12
13
import 'package:flutter_mqtt/ui/screens/fromdb/contact_page.dart' ;
13
14
import 'package:flutter_mqtt/ui/viewers/document_viewer.dart' ;
14
15
import 'package:flutter_mqtt/ui/viewers/media_viewer.dart' ;
16
+ import 'package:flutter_mqtt/ui/widgets/message_typing.dart' ;
15
17
import 'package:image_picker/image_picker.dart' ;
16
18
import 'package:mime/mime.dart' ;
17
19
import 'package:open_file/open_file.dart' ;
@@ -31,6 +33,7 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
31
33
bool isTyping = false ;
32
34
final subscriptions = List <StreamSubscription <dynamic >>.empty (growable: true );
33
35
types.User ? _user;
36
+ types.Message ? respondToMessage;
34
37
35
38
@override
36
39
void initState () {
@@ -155,7 +158,6 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
155
158
}
156
159
//TODO: Handle DOC/DOCX/ODT/...
157
160
//TODO: Handle TXT
158
- //TODO: HANDLE IMAGES
159
161
}
160
162
161
163
/*
@@ -182,9 +184,26 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
182
184
fromId: _user! .id,
183
185
sendTime: DateTime .now ().millisecondsSinceEpoch,
184
186
fromName: _user! .firstName);
185
- ChatApp .instance ()!
186
- .messageSender
187
- .sendChatMessage (nm, widget.contactChat.roomId);
187
+ if (respondToMessage == null ) {
188
+ ChatApp .instance ()!
189
+ .messageSender
190
+ .sendChatMessage (nm, widget.contactChat.roomId);
191
+ } else {
192
+ final rep = ChatMessage (
193
+ id: respondToMessage! .id,
194
+ text: (respondToMessage! is types.TextMessage )
195
+ ? (respondToMessage! as types.TextMessage ).text
196
+ : "File" ,
197
+ type: MessageType .ChatText ,
198
+ sendTime: respondToMessage! .createdAt ?? 0 ,
199
+ roomId: widget.contactChat.roomId);
200
+ ChatApp .instance ()!
201
+ .messageSender
202
+ .replyToMessage (rep, nm, widget.contactChat.roomId);
203
+ setState (() {
204
+ respondToMessage = null ;
205
+ });
206
+ }
188
207
}
189
208
190
209
@override
@@ -193,11 +212,12 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
193
212
appBar: AppBar (
194
213
centerTitle: false ,
195
214
title: InkWell (
196
- onTap: (){
215
+ onTap: () {
197
216
Navigator .push (
198
217
context,
199
218
MaterialPageRoute (
200
- builder: (context) => ContactDetailsPage (contactChat: widget.contactChat)),
219
+ builder: (context) =>
220
+ ContactDetailsPage (contactChat: widget.contactChat)),
201
221
);
202
222
},
203
223
child: Row (
@@ -249,9 +269,10 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
249
269
//onPreviewDataFetched: _handlePreviewDataFetched,
250
270
onSendPressed: _handleSendPressed,
251
271
onTextChanged: _handleTextChanged,
272
+ onMessageLongPress: _handleLongPress,
252
273
showUserNames: true ,
253
274
showUserAvatars: true ,
254
-
275
+ customBottomWidget : bottom (),
255
276
user: _user! ,
256
277
);
257
278
}
@@ -260,6 +281,20 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
260
281
);
261
282
}
262
283
284
+ Widget bottom () {
285
+ return MessageTyping (
286
+ topWidget: respondToMessage != null
287
+ ? respondToMessage! .toRespondedWidget (() => {
288
+ setState (() {
289
+ respondToMessage = null ;
290
+ })
291
+ })
292
+ : null ,
293
+ onSendPressed: _handleSendPressed,
294
+ onTextChanged: _handleTextChanged,
295
+ onAttachmentPressed: _handleAtachmentPressed);
296
+ }
297
+
263
298
void _handleTextChanged (String text) {
264
299
if (text.length > 0 && text.length % 3 == 0 ) {
265
300
ChatApp .instance ()!
@@ -275,4 +310,37 @@ class _ChatUIPageState extends State<ChatUIDBPage> {
275
310
});
276
311
super .dispose ();
277
312
}
313
+
314
+ void _handleLongPress (types.Message message) {
315
+ showCupertinoModalPopup <void >(
316
+ context: context,
317
+ builder: (BuildContext context) => CupertinoActionSheet (
318
+ title: const Text ('Title' ),
319
+ message: const Text ('Message' ),
320
+ actions: < CupertinoActionSheetAction > [
321
+ CupertinoActionSheetAction (
322
+ child: const Text ('Reply' ),
323
+ onPressed: () {
324
+ setState (() {
325
+ respondToMessage = message;
326
+ });
327
+ Navigator .pop (context);
328
+ },
329
+ ),
330
+ CupertinoActionSheetAction (
331
+ child: const Text ('Forward' ),
332
+ onPressed: () {
333
+ Navigator .pop (context);
334
+ },
335
+ ),
336
+ CupertinoActionSheetAction (
337
+ child: const Text ('Delete' ),
338
+ onPressed: () {
339
+ Navigator .pop (context);
340
+ },
341
+ )
342
+ ],
343
+ ),
344
+ );
345
+ }
278
346
}
0 commit comments