From fc56f7af2abdc66feb7ed792970a9747c76219ed Mon Sep 17 00:00:00 2001 From: Abinanthankv Date: Fri, 10 Jan 2025 14:18:59 +0530 Subject: [PATCH] Update connection_list.dart --- .../library/containers/connection_list.dart | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/lib/features/library/containers/connection_list.dart b/lib/features/library/containers/connection_list.dart index ba369e7..0c25357 100644 --- a/lib/features/library/containers/connection_list.dart +++ b/lib/features/library/containers/connection_list.dart @@ -113,39 +113,44 @@ class _ConnectionCardState extends State { style: const TextStyle(fontWeight: FontWeight.bold)), trailing: widget.canDisconnect ? TextButton( - onPressed: () => showDialog( - builder: (ctx) { - return AlertDialog( - title: const Text("Confirmation"), - content: SizedBox( - width: MediaQuery.of(context).size.width, - child: Text( - "Are your sure you want to delete ${widget.connection.title}?", - ), - ), - actions: [ - ElevatedButton( - onPressed: () { - Navigator.of(ctx).pop(); - }, - child: const Text("CANCEL"), - ), - FilledButton( - onPressed: () { - _handleConnection(context, ref); - Navigator.of(context).pop(); - }, - child: const Text("DISCONNECT"), - ), - ], - ); - }, - context: context, - ), - child: isLoading - ? const CircularProgressIndicator() - : const Text("Disconnect"), - ) + onPressed: () async { // Make onPressed async + final result = await showDialog( // Await the dialog result + context: context, + builder: (ctx) { + return AlertDialog( + title: const Text("Confirmation"), + content: SizedBox( + width: MediaQuery.of(context).size.width, + child: Text( + "Are you sure you want to delete ${widget.connection.title}?", + ), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(ctx).pop(false); // Return false on cancel + }, + child: const Text("CANCEL"), + ), + FilledButton( + onPressed: () { + Navigator.of(ctx).pop(true); // Return true on disconnect + }, + child: const Text("DISCONNECT"), + ), + ], + ); + }, + ); + + if (result == true) { // Check if the user pressed disconnect + _handleConnection(context, ref); + } + }, + child: isLoading + ? const CircularProgressIndicator() + : const Text("Disconnect"), + ) : null, ), );