diff --git a/lib/home_page.dart b/lib/home_page.dart index ea472c7..f4e67f7 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -29,6 +29,8 @@ class _HomeScreenState extends State with TickerProviderStateMixin { ]; bool _checkboxState = false; bool bulkOptionsState = false; + List selectedThreads = + []; //this should store the emails that are being stored downstream too List _tabs = ['Emails']; Map _tabWidgets = {}; @@ -40,6 +42,11 @@ class _HomeScreenState extends State with TickerProviderStateMixin { _tabController = TabController(length: _tabs.length, vsync: this); _tabWidgets['Emails'] = EmailPage( key: _emailPageKey, + onSelectionChanged: (updatedList) { + setState(() { + selectedThreads = updatedList; + }); + }, ); } @@ -354,24 +361,45 @@ class _HomeScreenState extends State with TickerProviderStateMixin { Icons.arrow_drop_down_outlined), itemBuilder: (BuildContext context) => >[ - const PopupMenuItem( - child: Text("All")), - const PopupMenuItem( - child: Text("None")), - const PopupMenuItem( - child: Text("Read")), - const PopupMenuItem( - child: Text("Unread")), - const PopupMenuItem( + PopupMenuItem( + //select all + child: Text("All"), + onTap: () { + _emailPageKey.currentState! + .selectAllEmails(true); + }, + ), + PopupMenuItem( + child: Text("None"), + onTap: () { + _emailPageKey.currentState! + .selectAllEmails(false); + }, + ), + PopupMenuItem( + child: Text("Read"), + onTap: () { + //select the read + }, + ), + PopupMenuItem( + //select the unread + child: Text("Unread"), + onTap: () { + //select the unread + }, + ), + PopupMenuItem( child: Text("Starred")), - const PopupMenuItem( + PopupMenuItem( child: Text("Unstarred")), ], onSelected: (String result) { print("result $result"); }, ), - if (bulkOptionsState) ...[ + if (selectedThreads.isNotEmpty) ...[ + //this needs to know if anything got selected, IconButton( onPressed: null, icon: Icon(Icons.archive_outlined)), @@ -379,7 +407,11 @@ class _HomeScreenState extends State with TickerProviderStateMixin { onPressed: null, icon: Icon(Icons.delete_outlined)), IconButton( - onPressed: null, + onPressed: () { + _emailPageKey.currentState! + .markSelectedAsRead( + true); //mark as read + }, icon: Icon( Icons.mark_email_read_outlined)), IconButton( @@ -390,9 +422,10 @@ class _HomeScreenState extends State with TickerProviderStateMixin { PopupMenuButton( icon: const Icon(Icons.more_vert), itemBuilder: (BuildContext context) { - if (!bulkOptionsState) { + if (selectedThreads.isEmpty) { + //why tf? return >[ - const PopupMenuItem( + PopupMenuItem( child: Row( children: [ Icon(Icons @@ -403,19 +436,28 @@ class _HomeScreenState extends State with TickerProviderStateMixin { Text("Mark all as read") ], ), + onTap: () { + _emailPageKey.currentState! + .selectAllEmails(true); + _emailPageKey.currentState! + .markSelectedAsRead(true); + _emailPageKey.currentState! + .selectAllEmails(false); + }, ), const PopupMenuDivider(), PopupMenuItem( - child: Text( - "Select messages to see more actions", - style: TextStyle( - color: Colors - .blueGrey.shade300), - )) + child: Text( + "Select messages to see more actions", + style: TextStyle( + color: Colors + .blueGrey.shade300), + ), + ) ]; } else { return >[ - const PopupMenuItem( + PopupMenuItem( child: Row( children: [ Icon(Icons @@ -426,28 +468,34 @@ class _HomeScreenState extends State with TickerProviderStateMixin { Text("Mark as unread") ], ), + onTap: () { + _emailPageKey.currentState! + .markSelectedAsRead( + false); + }, ), const PopupMenuItem( - child: Row( - children: [ - Icon(Icons.snooze_outlined), - const SizedBox( - width: 4.0, - ), - Text("Snooze") - ], - ), + child: Row( + children: [ + Icon(Icons.snooze_outlined), + const SizedBox( + width: 4.0, + ), + Text("Snooze") + ], + ), ), const PopupMenuItem( - child: Row( - children: [ - Icon(Icons.star_border_outlined), - const SizedBox( - width: 4.0, - ), - Text("Add star") - ], - ), + child: Row( + children: [ + Icon(Icons + .star_border_outlined), + const SizedBox( + width: 4.0, + ), + Text("Add star") + ], + ), ), ]; }