select emails in bulk and each, select all and unselect
This commit is contained in:
parent
71707bd1c0
commit
5d4854901e
121
lib/email.dart
121
lib/email.dart
@ -3,36 +3,118 @@ import 'api_service.dart';
|
|||||||
import 'structs.dart';
|
import 'structs.dart';
|
||||||
import 'emailView.dart';
|
import 'emailView.dart';
|
||||||
|
|
||||||
class EmailListScreen extends StatelessWidget {
|
class EmailListScreen extends StatefulWidget {
|
||||||
final List<GetThreadResponse> emails;
|
final List<GetThreadResponse> emails;
|
||||||
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;
|
||||||
|
|
||||||
EmailListScreen(
|
EmailListScreen({
|
||||||
{required this.emails,
|
required this.key,
|
||||||
|
required this.emails,
|
||||||
required this.getEmailContent,
|
required this.getEmailContent,
|
||||||
required this.folder});
|
required this.folder})
|
||||||
//fix the email list
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_EmailListScreenState createState() => _EmailListScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EmailListScreenState extends State<EmailListScreen> {
|
||||||
|
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
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
selectStates = List<bool>.filled(widget.emails.length, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant EmailListScreen oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (oldWidget.emails.length != widget.emails.length) {
|
||||||
|
selectStates = List<bool>.filled(widget.emails.length, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool selectAllChecks(bool selectionType) {
|
||||||
|
setState(() {
|
||||||
|
for (int email = 0; email < selectStates.length; email++) {
|
||||||
|
selectStates[email] = selectionType;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
printTheSelected();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printTheSelected() {
|
||||||
|
for (int i = 0; i < selectedEmails.length; i++) {
|
||||||
|
print(selectedEmails);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: ListView.separated(
|
body: ListView.separated(
|
||||||
itemCount: emails.length,
|
itemCount: widget.emails.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final email = emails[index];
|
final email = widget.emails[index];
|
||||||
return ListTile(
|
|
||||||
|
return MouseRegion(
|
||||||
|
onEnter: (_) => setState(() => _hoveredRows.add(index)),
|
||||||
|
onExit: (_) => setState(() => _hoveredRows.remove(index)),
|
||||||
|
child: ListTile(
|
||||||
|
leading: Checkbox(
|
||||||
|
value: selectStates[index],
|
||||||
|
onChanged: (bool? value) {
|
||||||
|
setState(() {
|
||||||
|
//works great
|
||||||
|
selectStates[index] = value ?? false;
|
||||||
|
if (value!) {
|
||||||
|
selectedEmails.add(widget.emails[index]);
|
||||||
|
} else {
|
||||||
|
selectedEmails.remove(widget.emails[index]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
title: Text(email.from_name,
|
title: Text(email.from_name,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
subtitle: Column(
|
subtitle: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [Text(email.subject)],
|
children: [Text(email.subject)],
|
||||||
),
|
),
|
||||||
trailing: Text(email.date.toString()),
|
trailing: _hoveredRows.contains(index)
|
||||||
|
? Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.mark_email_read_outlined),
|
||||||
|
onPressed: () {
|
||||||
|
//mark email as read
|
||||||
|
},
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.delete_outline),
|
||||||
|
onPressed: () {
|
||||||
|
//delete email
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Text(email.date.toString()),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
List<String> emailContent = // list of the html
|
List<String> emailContent = // list of the html
|
||||||
await getEmailContent(email.messages, folder);
|
await widget.getEmailContent(email.messages, widget.folder);
|
||||||
|
|
||||||
print(email.messages); //email ids of the thread
|
print(email.messages); //email ids of the thread
|
||||||
|
if (widget.folder == "Drafts") {
|
||||||
|
print("IN DRAFTS MOVE THE CONTENT TO THE WRITING THING");
|
||||||
|
} else {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@ -49,7 +131,9 @@ class EmailListScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) => Divider(),
|
separatorBuilder: (context, index) => Divider(),
|
||||||
@ -76,6 +160,9 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
int page = 1;
|
int page = 1;
|
||||||
bool isBackDisabled = false;
|
bool isBackDisabled = false;
|
||||||
|
|
||||||
|
final GlobalKey<_EmailListScreenState> emailListKey = GlobalKey<_EmailListScreenState>();
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -84,6 +171,7 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
_fetchEmails();
|
_fetchEmails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<GetThreadResponse> get getEmails => emails;
|
||||||
String getPage() => widget.page.toString();
|
String getPage() => widget.page.toString();
|
||||||
bool get backDisabled => isBackDisabled;
|
bool get backDisabled => isBackDisabled;
|
||||||
|
|
||||||
@ -114,7 +202,6 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// print(currentPage);
|
|
||||||
print(widget.page);
|
print(widget.page);
|
||||||
_fetchEmails();
|
_fetchEmails();
|
||||||
}
|
}
|
||||||
@ -133,15 +220,19 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool selectAllEmails(bool selectionType) {
|
||||||
|
emailListKey.currentState?.selectAllChecks(selectionType);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(body: EmailListScreen(
|
||||||
body: EmailListScreen(
|
key: emailListKey,
|
||||||
emails: emails,
|
emails: emails,
|
||||||
// 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
|
||||||
),
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user