|
@@ -9,35 +9,63 @@ class HomeScreen extends StatefulWidget {
|
|
_HomeScreenState createState() => _HomeScreenState();
|
|
_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<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
|
|
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
|
|
ApiService apiService = ApiService();
|
|
ApiService apiService = ApiService();
|
|
bool _isSidebarOpen = true;
|
|
bool _isSidebarOpen = true;
|
|
bool querySearches = false;
|
|
bool querySearches = false;
|
|
|
|
|
|
- List<String> _tabs = ['INBOX', 'Search'];
|
|
|
|
|
|
+ List<String> _tabs = ['INBOX'];
|
|
|
|
+ Map<String, Widget> _tabWidgets = {};
|
|
TabController? _tabController;
|
|
TabController? _tabController;
|
|
|
|
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
super.initState();
|
|
super.initState();
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
_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) {
|
|
void _performSearch(String query) {
|
|
setState(() {
|
|
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
|
|
// Remove a tab
|
|
void _removeTab(int index) {
|
|
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
|
|
@override
|
|
@@ -46,7 +74,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
|
|
super.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
return Scaffold(
|
|
@@ -166,7 +193,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
|
|
// setState(() {
|
|
// setState(() {
|
|
// querySearches = true;
|
|
// querySearches = true;
|
|
// });
|
|
// });
|
|
-
|
|
|
|
},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
@@ -230,7 +256,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
|
|
},
|
|
},
|
|
child: Icon(Icons.navigate_next),
|
|
child: Icon(Icons.navigate_next),
|
|
),
|
|
),
|
|
-
|
|
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
@@ -238,11 +263,16 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
|
|
child: TabBarView(
|
|
child: TabBarView(
|
|
controller: _tabController,
|
|
controller: _tabController,
|
|
children: _tabs.map((tab) {
|
|
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(),
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
-
|
|
|
|
|
|
+
|
|
// if (_tabs.isEmpty)
|
|
// if (_tabs.isEmpty)
|
|
// Expanded(
|
|
// Expanded(
|
|
// child: EmailPage(key: _emailPageKey),
|
|
// child: EmailPage(key: _emailPageKey),
|