12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import 'package:flutter/material.dart';
- import 'api_service.dart';
- import 'structs.dart';
- class SerializableMessageListScreen extends StatefulWidget {
- @override
- _SerializableMessageListScreenState createState() => _SerializableMessageListScreenState();
- }
- class _SerializableMessageListScreenState extends State<SerializableMessageListScreen> {
- List<SerializableMessage>? messages;
- bool isLoading = true;
- bool hasError = false;
- final ApiService apiService = ApiService();
- @override
- void initState() {
- super.initState();
- _fetchMessages();
- }
- Future<void> _fetchMessages() async {
- try {
- List<SerializableMessage> fetchedMessages = await apiService.sonicSearch("INBOX", 10, 0, "searchQuery");
- setState(() {
- messages = fetchedMessages;
- isLoading = false;
- });
- } catch (e) {
- setState(() {
- hasError = true;
- isLoading = false;
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- if (isLoading) {
- return Center(child: CircularProgressIndicator());
- }
- if (hasError) {
- return Center(child: Text("Error fetching messages."));
- }
- if (messages == null || messages!.isEmpty) {
- return Center(child: Text("No messages found."));
- }
- return ListView.separated(
- itemCount: messages!.length,
- itemBuilder: (context, index) {
- final message = messages![index];
- return ListTile(
- title: Text(message.name, style: TextStyle(fontWeight: FontWeight.bold)),
- subtitle: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [Text(message.subject)],
- ),
- trailing: Text(message.date),
- onTap: () async {
- String emailContent = await apiService.fetchEmailContent([message.id]);
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => EmailView(
- emailContent: emailContent,
- from: message.from,
- name: message.name,
- to: message.to.toString(),
- subject: message.subject,
- date: message.date,
- id: message.id,
- ),
- ),
- );
- },
- );
- },
- separatorBuilder: (context, index) => Divider(),
- );
- }
- }
|