From eebde52d0447afed05671392dcd38b8ddcee6bfb Mon Sep 17 00:00:00 2001
From: Sara <sarasdj@stud.ntnu.no>
Date: Wed, 10 Apr 2024 15:01:11 +0200
Subject: [PATCH] update: search selection

---
 app/lib/pages/default_page.dart           | 14 ++------------
 app/lib/utils/custom_search_delegate.dart | 15 +++++++--------
 2 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/app/lib/pages/default_page.dart b/app/lib/pages/default_page.dart
index b9c1d308..ca25bf5f 100644
--- a/app/lib/pages/default_page.dart
+++ b/app/lib/pages/default_page.dart
@@ -64,20 +64,10 @@ class _DefaultPageState extends State<DefaultPage> {
                 showSearch( // Fetch new relation and measurements on search
                   context: context,
                   delegate: CustomSearchDelegate((String result) {
-                    setState(() async {
-                      selectedRelation = await fetchRelation();
-                      selectedMarkerList = await fetchMeasurements().then((fetchResult) {
-                        List<Measurement> measurements = fetchResult.measurements;
-                        serverConnection = fetchResult.connected;
-
-                        // Return the measurements
-                        return measurements;
-                      }).catchError((error) {
-                        serverConnection = false;
-                        throw Exception("Failed to fetch measurements: $error");
-                      });
+                    setState(() {
                       selectedLake = result;
                     });
+                    initialiseState();
                   }),
                 );
               },
diff --git a/app/lib/utils/custom_search_delegate.dart b/app/lib/utils/custom_search_delegate.dart
index 798c4c0b..09886e07 100644
--- a/app/lib/utils/custom_search_delegate.dart
+++ b/app/lib/utils/custom_search_delegate.dart
@@ -44,14 +44,9 @@ class CustomSearchDelegate extends SearchDelegate {
       itemCount: searchResults.length,
       itemBuilder: (context, index) {
         var result = searchResults[index];
-        return GestureDetector(
-          onTap: () {
-            onResultSelected(result);
-            close(context, result);
-          },
-          child: ListTile(
-            title: Text(result),
-          ),
+        return ListTile(
+          title: Text(result),
+          tileColor: Colors.red,
         );
       },
     );
@@ -72,6 +67,10 @@ class CustomSearchDelegate extends SearchDelegate {
         if  (searchResults.isNotEmpty) {
           return ListTile(
             title: Text(result),
+            onTap: () {
+              onResultSelected(result);
+              close(context, result);
+            },
           );
         }
         else {
-- 
GitLab