markselectedAsRead, onSelectionChanged callback, adding tickerproviderStateMixin, fix bugs, mark as rad, true and false
This commit is contained in:
parent
0874ffa98e
commit
0bfc869e74
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markdown/markdown.dart' as md;
|
||||
import 'api_service.dart';
|
||||
import 'structs.dart';
|
||||
import 'emailView.dart';
|
||||
@ -8,24 +9,28 @@ class EmailListScreen extends StatefulWidget {
|
||||
final Future<List<String>> Function(List<String>, String) getEmailContent;
|
||||
final String folder;
|
||||
final GlobalKey<_EmailListScreenState> key;
|
||||
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
||||
|
||||
EmailListScreen(
|
||||
{required this.key,
|
||||
EmailListScreen({
|
||||
required this.key,
|
||||
required this.emails,
|
||||
required this.getEmailContent,
|
||||
required this.folder})
|
||||
: super(key: key);
|
||||
required this.folder,
|
||||
this.onSelectionChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_EmailListScreenState createState() => _EmailListScreenState();
|
||||
}
|
||||
|
||||
class _EmailListScreenState extends State<EmailListScreen> {
|
||||
class _EmailListScreenState extends State<EmailListScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late List<bool> selectStates; // for checkboxes if its selected or not
|
||||
late List<GetThreadResponse> selectedEmails =
|
||||
[]; // holds the emails that are selected i.e. the emails that got the checkbox on
|
||||
final Set<int> _hoveredRows = {}; //the row that is being hovered over atm
|
||||
bool bulkSelectMenu = false;
|
||||
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -42,21 +47,57 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
||||
}
|
||||
|
||||
bool selectAllChecks(bool selectionType) {
|
||||
//perhaps it should return a list of the selected
|
||||
setState(() {
|
||||
selectedEmails = [];
|
||||
if (selectionType) {
|
||||
bulkSelectMenu = true;
|
||||
for (int email = 0; email < selectStates.length; email++) {
|
||||
selectStates[email] = selectionType;
|
||||
selectedEmails.add(widget.emails[email]);
|
||||
}
|
||||
} else {
|
||||
for (int email = 0; email < selectStates.length; email++) {
|
||||
selectStates[email] = selectionType;
|
||||
}
|
||||
selectedEmails = [];
|
||||
}
|
||||
});
|
||||
widget.onSelectionChanged?.call(selectedEmails);
|
||||
printTheSelected();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool markAsRead(bool read) {
|
||||
print("markasread $read");
|
||||
setState(() {
|
||||
if (read) {
|
||||
//read
|
||||
for (int email = 0; email < selectedEmails.length; email++) {
|
||||
selectedEmails[email].seen = read;
|
||||
ApiService()
|
||||
.markAsSeen(selectedEmails[email].id); //the remote or .json
|
||||
}
|
||||
} else {
|
||||
//unread
|
||||
for (int email = 0; email < selectedEmails.length; email++) {
|
||||
selectedEmails[email].seen = read;
|
||||
ApiService()
|
||||
.markAsUnseen(selectedEmails[email].id); //the remote or .json
|
||||
print(selectedEmails[email].subject);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
List<GetThreadResponse> listOfSelectedThreads() {
|
||||
return selectedEmails;
|
||||
}
|
||||
|
||||
void printTheSelected() {
|
||||
for (int i = 0; i < selectedEmails.length; i++) {
|
||||
print(selectedEmails);
|
||||
print(selectedEmails[i].subject);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,11 +124,19 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
||||
setState(() {
|
||||
//works great
|
||||
selectStates[index] = value ?? false;
|
||||
|
||||
setState(() {
|
||||
if (value!) {
|
||||
selectedEmails.add(widget.emails[index]);
|
||||
//here i must update the other side
|
||||
_emailPageKey.currentState?.getListOfSelected();
|
||||
} else {
|
||||
selectedEmails.remove(widget.emails[index]);
|
||||
_emailPageKey.currentState?.getListOfSelected();
|
||||
}
|
||||
widget.onSelectionChanged?.call(selectedEmails);
|
||||
print(selectedEmails);
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -97,7 +146,6 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [Text(email.subject)],
|
||||
),
|
||||
// tileColor: () ,
|
||||
trailing: _hoveredRows.contains(index)
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -161,10 +209,12 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class EmailPage extends StatefulWidget {
|
||||
EmailPage({Key? key}) : super(key: key);
|
||||
String selectedFolder = "INBOX"; //starter
|
||||
int offset = 0;
|
||||
int page = 1;
|
||||
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
||||
|
||||
EmailPage({Key? key, this.onSelectionChanged}) : super(key: key);
|
||||
|
||||
@override
|
||||
EmailPageState createState() => EmailPageState();
|
||||
@ -239,9 +289,19 @@ class EmailPageState extends State<EmailPage> {
|
||||
|
||||
bool selectAllEmails(bool selectionType) {
|
||||
emailListKey.currentState?.selectAllChecks(selectionType);
|
||||
return false;
|
||||
return selectionType;
|
||||
}
|
||||
|
||||
bool markSelectedAsRead(bool selectionType) {
|
||||
emailListKey.currentState?.markAsRead(selectionType);
|
||||
return selectionType;
|
||||
}
|
||||
|
||||
List<GetThreadResponse> getListOfSelected() {
|
||||
return emailListKey.currentState!.listOfSelectedThreads() ?? [];
|
||||
}
|
||||
// return [GetThreadResponse(id: 1, messages: [], subject: "subject", date: DateTime(2025), from_name: "from_name", from_address: "from_address", to: [], seen: false)];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -251,6 +311,7 @@ class EmailPageState extends State<EmailPage> {
|
||||
// getEmailContent: apiService.fetchEmailContent,
|
||||
getEmailContent: apiService.fetchMarkdownContent,
|
||||
folder: widget.selectedFolder, //try to grab from it directly
|
||||
onSelectionChanged: widget.onSelectionChanged,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user