Bladeren bron

made tabs for each result, (they return all not found for now)

juan 1 maand geleden
bovenliggende
commit
747f84a2b7
1 gewijzigde bestanden met toevoegingen van 44 en 14 verwijderingen
  1. 44 14
      lib/home_page.dart

+ 44 - 14
lib/home_page.dart

@@ -9,35 +9,63 @@ class HomeScreen extends StatefulWidget {
   _HomeScreenState createState() => _HomeScreenState();
 }
 
-class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
+class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
   final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
   final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
   ApiService apiService = ApiService();
   bool _isSidebarOpen = true;
   bool querySearches = false;
 
-  List<String> _tabs = ['INBOX', 'Search'];
+  List<String> _tabs = ['INBOX'];
+  Map<String, Widget> _tabWidgets = {};
   TabController? _tabController;
 
   @override
   void initState() {
     super.initState();
     _tabController = TabController(length: _tabs.length, vsync: this);
+    _tabWidgets['INBOX'] = EmailPage(
+      key: _emailPageKey,
+    );
   }
-   // Add a new tab based on the search
+
+  // Add a new tab based on the search
   void _performSearch(String query) {
     setState(() {
-      _tabs.add(query);
-      _tabController = TabController(length: _tabs.length, vsync: this);
+      if (!_tabs.contains(query)) {
+        _tabs.add(query);
+        _tabWidgets[query] = _buildSearchResultsWidget(
+            query); // Store a different widget for this tab
+        _tabController = TabController(length: _tabs.length, vsync: this);
+      }
     });
   }
 
   // Remove a tab
   void _removeTab(int index) {
-    setState(() {
-      _tabs.removeAt(index);
-      _tabController = TabController(length: _tabs.length, vsync: this);
-    });
+    if (_tabs[index] != 'INBOX') {
+      setState(() {
+        String tabToRemove = _tabs[index];
+        _tabs.removeAt(index);
+        _tabWidgets
+            .remove(tabToRemove); // Remove widget associated with the tab
+        _tabController = TabController(length: _tabs.length, vsync: this);
+      });
+    }
+  }
+
+  // Build a custom widget for each search query
+  Widget _buildSearchResultsWidget(String query) {
+    return Center(
+      child: Column(
+        mainAxisAlignment: MainAxisAlignment.center,
+        children: [
+          Text("Results for: $query", style: TextStyle(fontSize: 24)),
+          // You can add a list or any custom widget here
+          Text("Here you can display search results or other content."),
+        ],
+      ),
+    );
   }
 
   @override
@@ -46,7 +74,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
     super.dispose();
   }
 
-
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -166,7 +193,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                                 // setState(() {
                                 //   querySearches = true;
                                 // });
-
                               },
                             ),
                           ),
@@ -230,7 +256,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                             },
                             child: Icon(Icons.navigate_next),
                           ),
-                          
                         ],
                       ),
                     ),
@@ -238,11 +263,16 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                       child: TabBarView(
                         controller: _tabController,
                         children: _tabs.map((tab) {
-                          return Center(child: EmailPage(key: _emailPageKey,));
+                          return _tabWidgets[tab] ??
+                              Center(child: Text("No content found"));
+                          // return Center(
+                          //     child: EmailPage(
+                          //   key: _emailPageKey,
+                          // ));
                         }).toList(),
                       ),
                     ),
-                    
+
                     // if (_tabs.isEmpty)
                     //   Expanded(
                     //     child: EmailPage(key: _emailPageKey),