|
@@ -1,8 +1,10 @@
|
|
import 'package:crab_ui/folder_drawer.dart';
|
|
import 'package:crab_ui/folder_drawer.dart';
|
|
|
|
+import 'package:crab_ui/structs.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'api_service.dart';
|
|
import 'api_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'email.dart';
|
|
import 'email.dart';
|
|
|
|
+// import 'serialize.dart';
|
|
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
class HomeScreen extends StatefulWidget {
|
|
@override
|
|
@override
|
|
@@ -34,8 +36,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
setState(() {
|
|
setState(() {
|
|
if (!_tabs.contains(query)) {
|
|
if (!_tabs.contains(query)) {
|
|
_tabs.add(query);
|
|
_tabs.add(query);
|
|
- _tabWidgets[query] = _buildSearchResultsWidget(
|
|
|
|
- query); // Store a different widget for this tab
|
|
|
|
|
|
+ _tabWidgets[query] = _buildSearchResultsWidget(query); // Store a different widget for this tab
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -56,16 +57,91 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
|
|
|
|
// Build a custom widget for each search query
|
|
// Build a custom widget for each search query
|
|
Widget _buildSearchResultsWidget(String 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."),
|
|
|
|
- ],
|
|
|
|
- ),
|
|
|
|
- );
|
|
|
|
|
|
+ // Future<List<SerializableMessage>> result = apiService.sonicSearch("INBOX", 10, 0, 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."),
|
|
|
|
+ // // Text(result[0].messages.toString()),
|
|
|
|
+ // Text(query),
|
|
|
|
+ // Text(result[0].name),
|
|
|
|
+ // ],
|
|
|
|
+ // ),
|
|
|
|
+ // );
|
|
|
|
+ return FutureBuilder<List<SerializableMessage>>(
|
|
|
|
+ future: apiService.sonicSearch("INBOX", 10, 0, query),
|
|
|
|
+ builder: (BuildContext context, AsyncSnapshot<List<SerializableMessage>> snapshot) {
|
|
|
|
+ if (snapshot.connectionState == ConnectionState.waiting) {
|
|
|
|
+ return Center(child: CircularProgressIndicator());
|
|
|
|
+ } else if (snapshot.hasError) {
|
|
|
|
+ return Center(child: Text('Error: ${snapshot.error}'));
|
|
|
|
+ } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
|
|
|
+ return Center(child: Text('No results found for: $query'));
|
|
|
|
+ } else {
|
|
|
|
+ List<SerializableMessage> result = snapshot.data!;
|
|
|
|
+ return Scaffold(
|
|
|
|
+ body: ListView.separated(
|
|
|
|
+ itemCount: result.length,
|
|
|
|
+ itemBuilder: (context, index){
|
|
|
|
+ final email = result[index];
|
|
|
|
+ return ListTile(
|
|
|
|
+ title: Text(email.from,
|
|
|
|
+ style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
+ subtitle: Column(
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
+ children: [Text(email.subject)],
|
|
|
|
+ ),
|
|
|
|
+ trailing: Text(email.date.toString()),
|
|
|
|
+ onTap: () async {
|
|
|
|
+ String emailContent = await apiService.fetchEmailContent(email.id as List<String>);
|
|
|
|
+ Navigator.push(
|
|
|
|
+ context,
|
|
|
|
+ MaterialPageRoute(
|
|
|
|
+ builder: (context) => EmailView(
|
|
|
|
+ emailContent: emailContent,
|
|
|
|
+ from: email.from,
|
|
|
|
+ name: email.name,
|
|
|
|
+ to: email.to.toString(),
|
|
|
|
+ subject: email.subject,
|
|
|
|
+ date: email.date.toString(),
|
|
|
|
+ id: email.id.toString(),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ separatorBuilder: (context, index) => Divider(),
|
|
|
|
+ ),
|
|
|
|
+ // child: Column(
|
|
|
|
+ // mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
+ // children: [
|
|
|
|
+ // Text("Results for: $query", style: TextStyle(fontSize: 24)),
|
|
|
|
+ // // Display the actual data
|
|
|
|
+ // Text(result[0].name), // Accessing the first result safely
|
|
|
|
+ // Text(result[0].from), // Displaying the 'from' field as an example
|
|
|
|
+ // Text(result[0].hash),
|
|
|
|
+ // Text(result[0].subject),
|
|
|
|
+ // Text(result[0].uid.toString()),
|
|
|
|
+ // Text(result[0].list),
|
|
|
|
+ // Text(result[0].id),
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // // Add more fields or customize the display
|
|
|
|
+ // // SerializableEmailListScreen(emails: result, getEmailContent: getEmailContent)
|
|
|
|
+ // // Expanded(
|
|
|
|
+
|
|
|
|
+ // // child:
|
|
|
|
+ // // ),
|
|
|
|
+ // ],
|
|
|
|
+ );
|
|
|
|
+ // );
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -84,31 +160,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
_emailPageKey.currentState?.updateSelectedFolder(folder);
|
|
_emailPageKey.currentState?.updateSelectedFolder(folder);
|
|
},
|
|
},
|
|
),
|
|
),
|
|
- // appBar: AppBar(
|
|
|
|
- // title: Text('Search with Tabs'),
|
|
|
|
- // bottom: _tabs.isNotEmpty
|
|
|
|
- // ? TabBar(
|
|
|
|
- // controller: _tabController,
|
|
|
|
- // isScrollable: true,
|
|
|
|
- // tabs: _tabs
|
|
|
|
- // .asMap()
|
|
|
|
- // .entries
|
|
|
|
- // .map((entry) => Tab(
|
|
|
|
- // child: Row(
|
|
|
|
- // children: [
|
|
|
|
- // Text(entry.value),
|
|
|
|
- // SizedBox(width: 8),
|
|
|
|
- // GestureDetector(
|
|
|
|
- // onTap: () => _removeTab(entry.key),
|
|
|
|
- // child: Icon(Icons.close, size: 16),
|
|
|
|
- // ),
|
|
|
|
- // ],
|
|
|
|
- // ),
|
|
|
|
- // ))
|
|
|
|
- // .toList(),
|
|
|
|
- // )
|
|
|
|
- // : null,
|
|
|
|
- // ),
|
|
|
|
|
|
+
|
|
body: Stack(
|
|
body: Stack(
|
|
children: [
|
|
children: [
|
|
Row(
|
|
Row(
|
|
@@ -264,7 +316,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|
controller: _tabController,
|
|
controller: _tabController,
|
|
children: _tabs.map((tab) {
|
|
children: _tabs.map((tab) {
|
|
return _tabWidgets[tab] ??
|
|
return _tabWidgets[tab] ??
|
|
- Center(child: Text("No content found"));
|
|
|
|
|
|
+ Center(child: Text("No content found"));
|
|
// return Center(
|
|
// return Center(
|
|
// child: EmailPage(
|
|
// child: EmailPage(
|
|
// key: _emailPageKey,
|
|
// key: _emailPageKey,
|