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:flutter/material.dart';
|
||||||
|
import 'package:markdown/markdown.dart' as md;
|
||||||
import 'api_service.dart';
|
import 'api_service.dart';
|
||||||
import 'structs.dart';
|
import 'structs.dart';
|
||||||
import 'emailView.dart';
|
import 'emailView.dart';
|
||||||
@ -8,24 +9,28 @@ class EmailListScreen extends StatefulWidget {
|
|||||||
final Future<List<String>> Function(List<String>, String) getEmailContent;
|
final Future<List<String>> Function(List<String>, String) getEmailContent;
|
||||||
final String folder;
|
final String folder;
|
||||||
final GlobalKey<_EmailListScreenState> key;
|
final GlobalKey<_EmailListScreenState> key;
|
||||||
|
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
||||||
|
|
||||||
EmailListScreen(
|
EmailListScreen({
|
||||||
{required this.key,
|
required this.key,
|
||||||
required this.emails,
|
required this.emails,
|
||||||
required this.getEmailContent,
|
required this.getEmailContent,
|
||||||
required this.folder})
|
required this.folder,
|
||||||
: super(key: key);
|
this.onSelectionChanged,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_EmailListScreenState createState() => _EmailListScreenState();
|
_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<bool> selectStates; // for checkboxes if its selected or not
|
||||||
late List<GetThreadResponse> selectedEmails =
|
late List<GetThreadResponse> selectedEmails =
|
||||||
[]; // holds the emails that are selected i.e. the emails that got the checkbox on
|
[]; // 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
|
final Set<int> _hoveredRows = {}; //the row that is being hovered over atm
|
||||||
bool bulkSelectMenu = false;
|
bool bulkSelectMenu = false;
|
||||||
|
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -42,21 +47,57 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool selectAllChecks(bool selectionType) {
|
bool selectAllChecks(bool selectionType) {
|
||||||
|
//perhaps it should return a list of the selected
|
||||||
setState(() {
|
setState(() {
|
||||||
|
selectedEmails = [];
|
||||||
if (selectionType) {
|
if (selectionType) {
|
||||||
bulkSelectMenu = true;
|
bulkSelectMenu = true;
|
||||||
}
|
for (int email = 0; email < selectStates.length; email++) {
|
||||||
for (int email = 0; email < selectStates.length; email++) {
|
selectStates[email] = selectionType;
|
||||||
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();
|
printTheSelected();
|
||||||
return false;
|
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() {
|
void printTheSelected() {
|
||||||
for (int i = 0; i < selectedEmails.length; i++) {
|
for (int i = 0; i < selectedEmails.length; i++) {
|
||||||
print(selectedEmails);
|
print(selectedEmails[i].subject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,11 +124,19 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
//works great
|
//works great
|
||||||
selectStates[index] = value ?? false;
|
selectStates[index] = value ?? false;
|
||||||
if (value!) {
|
|
||||||
selectedEmails.add(widget.emails[index]);
|
setState(() {
|
||||||
} else {
|
if (value!) {
|
||||||
selectedEmails.remove(widget.emails[index]);
|
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,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [Text(email.subject)],
|
children: [Text(email.subject)],
|
||||||
),
|
),
|
||||||
// tileColor: () ,
|
|
||||||
trailing: _hoveredRows.contains(index)
|
trailing: _hoveredRows.contains(index)
|
||||||
? Row(
|
? Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -161,10 +209,12 @@ class _EmailListScreenState extends State<EmailListScreen> {
|
|||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class EmailPage extends StatefulWidget {
|
class EmailPage extends StatefulWidget {
|
||||||
EmailPage({Key? key}) : super(key: key);
|
|
||||||
String selectedFolder = "INBOX"; //starter
|
String selectedFolder = "INBOX"; //starter
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
|
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
||||||
|
|
||||||
|
EmailPage({Key? key, this.onSelectionChanged}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
EmailPageState createState() => EmailPageState();
|
EmailPageState createState() => EmailPageState();
|
||||||
@ -239,9 +289,19 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
|
|
||||||
bool selectAllEmails(bool selectionType) {
|
bool selectAllEmails(bool selectionType) {
|
||||||
emailListKey.currentState?.selectAllChecks(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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -251,6 +311,7 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
// getEmailContent: apiService.fetchEmailContent,
|
// getEmailContent: apiService.fetchEmailContent,
|
||||||
getEmailContent: apiService.fetchMarkdownContent,
|
getEmailContent: apiService.fetchMarkdownContent,
|
||||||
folder: widget.selectedFolder, //try to grab from it directly
|
folder: widget.selectedFolder, //try to grab from it directly
|
||||||
|
onSelectionChanged: widget.onSelectionChanged,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user