@@ -192,14 +192,16 @@ class _MessageCardState extends State<MessageCard> {
192
192
icon: const Icon (Icons .copy_all_rounded,
193
193
color: Colors .blue, size: 26 ),
194
194
name: 'Copy Text' ,
195
- onTap: () async {
195
+ onTap: (ctx ) async {
196
196
await Clipboard .setData (
197
197
ClipboardData (text: widget.message.msg))
198
198
.then ((value) {
199
- //for hiding bottom sheet
200
- Navigator .pop (context);
199
+ if (ctx.mounted) {
200
+ //for hiding bottom sheet
201
+ Navigator .pop (ctx);
201
202
202
- Dialogs .showSnackbar (context, 'Text Copied!' );
203
+ Dialogs .showSnackbar (ctx, 'Text Copied!' );
204
+ }
203
205
});
204
206
})
205
207
:
@@ -208,17 +210,19 @@ class _MessageCardState extends State<MessageCard> {
208
210
icon: const Icon (Icons .download_rounded,
209
211
color: Colors .blue, size: 26 ),
210
212
name: 'Save Image' ,
211
- onTap: () async {
213
+ onTap: (ctx ) async {
212
214
try {
213
215
log ('Image Url: ${widget .message .msg }' );
214
216
await GallerySaver .saveImage (widget.message.msg,
215
217
albumName: 'We Chat' )
216
218
.then ((success) {
217
- //for hiding bottom sheet
218
- Navigator .pop (context);
219
- if (success != null && success) {
220
- Dialogs .showSnackbar (
221
- context, 'Image Successfully Saved!' );
219
+ if (ctx.mounted) {
220
+ //for hiding bottom sheet
221
+ Navigator .pop (ctx);
222
+ if (success != null && success) {
223
+ Dialogs .showSnackbar (
224
+ ctx, 'Image Successfully Saved!' );
225
+ }
222
226
}
223
227
});
224
228
} catch (e) {
@@ -239,11 +243,13 @@ class _MessageCardState extends State<MessageCard> {
239
243
_OptionItem (
240
244
icon: const Icon (Icons .edit, color: Colors .blue, size: 26 ),
241
245
name: 'Edit Message' ,
242
- onTap: () {
243
- //for hiding bottom sheet
244
- Navigator . pop (context );
246
+ onTap: (ctx ) {
247
+ if (ctx.mounted) {
248
+ _showMessageUpdateDialog (ctx );
245
249
246
- _showMessageUpdateDialog ();
250
+ //for hiding bottom sheet
251
+ // Navigator.pop(ctx);
252
+ }
247
253
}),
248
254
249
255
//delete option
@@ -252,10 +258,10 @@ class _MessageCardState extends State<MessageCard> {
252
258
icon: const Icon (Icons .delete_forever,
253
259
color: Colors .red, size: 26 ),
254
260
name: 'Delete Message' ,
255
- onTap: () async {
261
+ onTap: (ctx ) async {
256
262
await APIs .deleteMessage (widget.message).then ((value) {
257
263
//for hiding bottom sheet
258
- Navigator .pop (context );
264
+ if (ctx.mounted) Navigator .pop (ctx );
259
265
});
260
266
}),
261
267
@@ -270,27 +276,27 @@ class _MessageCardState extends State<MessageCard> {
270
276
_OptionItem (
271
277
icon: const Icon (Icons .remove_red_eye, color: Colors .blue),
272
278
name:
273
- 'Sent At: ${MyDateUtil .getMessageTime (context : context , time : widget .message .sent )}' ,
274
- onTap: () {}),
279
+ 'Sent At: ${MyDateUtil .getMessageTime (time : widget .message .sent )}' ,
280
+ onTap: (_ ) {}),
275
281
276
282
//read time
277
283
_OptionItem (
278
284
icon: const Icon (Icons .remove_red_eye, color: Colors .green),
279
285
name: widget.message.read.isEmpty
280
286
? 'Read At: Not seen yet'
281
- : 'Read At: ${MyDateUtil .getMessageTime (context : context , time : widget .message .read )}' ,
282
- onTap: () {}),
287
+ : 'Read At: ${MyDateUtil .getMessageTime (time : widget .message .read )}' ,
288
+ onTap: (_ ) {}),
283
289
],
284
290
);
285
291
});
286
292
}
287
293
288
294
//dialog for updating message content
289
- void _showMessageUpdateDialog () {
295
+ void _showMessageUpdateDialog (final BuildContext ctx ) {
290
296
String updatedMsg = widget.message.msg;
291
297
292
298
showDialog (
293
- context: context ,
299
+ context: ctx ,
294
300
builder: (_) => AlertDialog (
295
301
contentPadding: const EdgeInsets .only (
296
302
left: 24 , right: 24 , top: 20 , bottom: 10 ),
@@ -326,7 +332,7 @@ class _MessageCardState extends State<MessageCard> {
326
332
MaterialButton (
327
333
onPressed: () {
328
334
//hide alert dialog
329
- Navigator .pop (context );
335
+ Navigator .pop (ctx );
330
336
},
331
337
child: const Text (
332
338
'Cancel' ,
@@ -336,9 +342,12 @@ class _MessageCardState extends State<MessageCard> {
336
342
//update button
337
343
MaterialButton (
338
344
onPressed: () {
339
- //hide alert dialog
340
- Navigator .pop (context);
341
345
APIs .updateMessage (widget.message, updatedMsg);
346
+ //hide alert dialog
347
+ Navigator .pop (ctx);
348
+
349
+ //for hiding bottom sheet
350
+ Navigator .pop (ctx);
342
351
},
343
352
child: const Text (
344
353
'Update' ,
@@ -353,15 +362,15 @@ class _MessageCardState extends State<MessageCard> {
353
362
class _OptionItem extends StatelessWidget {
354
363
final Icon icon;
355
364
final String name;
356
- final VoidCallback onTap;
365
+ final Function ( BuildContext ) onTap;
357
366
358
367
const _OptionItem (
359
368
{required this .icon, required this .name, required this .onTap});
360
369
361
370
@override
362
371
Widget build (BuildContext context) {
363
372
return InkWell (
364
- onTap: () => onTap (),
373
+ onTap: () => onTap (context ),
365
374
child: Padding (
366
375
padding: EdgeInsets .only (
367
376
left: mq.width * .05 ,
0 commit comments