@@ -192,14 +192,16 @@ class _MessageCardState extends State<MessageCard> {
192192 icon: const Icon (Icons .copy_all_rounded,
193193 color: Colors .blue, size: 26 ),
194194 name: 'Copy Text' ,
195- onTap: () async {
195+ onTap: (ctx ) async {
196196 await Clipboard .setData (
197197 ClipboardData (text: widget.message.msg))
198198 .then ((value) {
199- //for hiding bottom sheet
200- Navigator .pop (context);
199+ if (ctx.mounted) {
200+ //for hiding bottom sheet
201+ Navigator .pop (ctx);
201202
202- Dialogs .showSnackbar (context, 'Text Copied!' );
203+ Dialogs .showSnackbar (ctx, 'Text Copied!' );
204+ }
203205 });
204206 })
205207 :
@@ -208,17 +210,19 @@ class _MessageCardState extends State<MessageCard> {
208210 icon: const Icon (Icons .download_rounded,
209211 color: Colors .blue, size: 26 ),
210212 name: 'Save Image' ,
211- onTap: () async {
213+ onTap: (ctx ) async {
212214 try {
213215 log ('Image Url: ${widget .message .msg }' );
214216 await GallerySaver .saveImage (widget.message.msg,
215217 albumName: 'We Chat' )
216218 .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+ }
222226 }
223227 });
224228 } catch (e) {
@@ -239,11 +243,13 @@ class _MessageCardState extends State<MessageCard> {
239243 _OptionItem (
240244 icon: const Icon (Icons .edit, color: Colors .blue, size: 26 ),
241245 name: 'Edit Message' ,
242- onTap: () {
243- //for hiding bottom sheet
244- Navigator . pop (context );
246+ onTap: (ctx ) {
247+ if (ctx.mounted) {
248+ _showMessageUpdateDialog (ctx );
245249
246- _showMessageUpdateDialog ();
250+ //for hiding bottom sheet
251+ // Navigator.pop(ctx);
252+ }
247253 }),
248254
249255 //delete option
@@ -252,10 +258,10 @@ class _MessageCardState extends State<MessageCard> {
252258 icon: const Icon (Icons .delete_forever,
253259 color: Colors .red, size: 26 ),
254260 name: 'Delete Message' ,
255- onTap: () async {
261+ onTap: (ctx ) async {
256262 await APIs .deleteMessage (widget.message).then ((value) {
257263 //for hiding bottom sheet
258- Navigator .pop (context );
264+ if (ctx.mounted) Navigator .pop (ctx );
259265 });
260266 }),
261267
@@ -270,27 +276,27 @@ class _MessageCardState extends State<MessageCard> {
270276 _OptionItem (
271277 icon: const Icon (Icons .remove_red_eye, color: Colors .blue),
272278 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: (_ ) {}),
275281
276282 //read time
277283 _OptionItem (
278284 icon: const Icon (Icons .remove_red_eye, color: Colors .green),
279285 name: widget.message.read.isEmpty
280286 ? '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: (_ ) {}),
283289 ],
284290 );
285291 });
286292 }
287293
288294 //dialog for updating message content
289- void _showMessageUpdateDialog () {
295+ void _showMessageUpdateDialog (final BuildContext ctx ) {
290296 String updatedMsg = widget.message.msg;
291297
292298 showDialog (
293- context: context ,
299+ context: ctx ,
294300 builder: (_) => AlertDialog (
295301 contentPadding: const EdgeInsets .only (
296302 left: 24 , right: 24 , top: 20 , bottom: 10 ),
@@ -326,7 +332,7 @@ class _MessageCardState extends State<MessageCard> {
326332 MaterialButton (
327333 onPressed: () {
328334 //hide alert dialog
329- Navigator .pop (context );
335+ Navigator .pop (ctx );
330336 },
331337 child: const Text (
332338 'Cancel' ,
@@ -336,9 +342,12 @@ class _MessageCardState extends State<MessageCard> {
336342 //update button
337343 MaterialButton (
338344 onPressed: () {
339- //hide alert dialog
340- Navigator .pop (context);
341345 APIs .updateMessage (widget.message, updatedMsg);
346+ //hide alert dialog
347+ Navigator .pop (ctx);
348+
349+ //for hiding bottom sheet
350+ Navigator .pop (ctx);
342351 },
343352 child: const Text (
344353 'Update' ,
@@ -353,15 +362,15 @@ class _MessageCardState extends State<MessageCard> {
353362class _OptionItem extends StatelessWidget {
354363 final Icon icon;
355364 final String name;
356- final VoidCallback onTap;
365+ final Function ( BuildContext ) onTap;
357366
358367 const _OptionItem (
359368 {required this .icon, required this .name, required this .onTap});
360369
361370 @override
362371 Widget build (BuildContext context) {
363372 return InkWell (
364- onTap: () => onTap (),
373+ onTap: () => onTap (context ),
365374 child: Padding (
366375 padding: EdgeInsets .only (
367376 left: mq.width * .05 ,
0 commit comments