add the compose widget to sidebar

This commit is contained in:
Juan Marulanda De Los Rios 2025-07-23 10:29:13 -04:00
parent 214a60ce1b
commit c025fbe07a

View File

@ -5,6 +5,7 @@ import 'structs.dart';
import 'api_service.dart'; import 'api_service.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'email.dart'; import 'email.dart';
import 'Compose.dart';
class HomeScreen extends StatefulWidget { class HomeScreen extends StatefulWidget {
@override @override
@ -44,50 +45,51 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
}); });
} }
void _showOptionsSearchDialog () async { void _showOptionsSearchDialog() async {
List<String> folders = await apiService.fetchFolders(); List<String> folders = await apiService.fetchFolders();
if (mounted) { if (mounted) {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text('Choose an Option'), title: Text('Choose an Option'),
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: folders.map((option) { children: folders.map((option) {
return ListTile( return ListTile(
title: Text(option), title: Text(option),
leading: Radio<String>( leading: Radio<String>(
value: option, value: option,
groupValue: _selectedOption, // Bind with _selectedOption groupValue: _selectedOption, // Bind with _selectedOption
onChanged: (String? value) { onChanged: (String? value) {
setState(() { setState(() {
_selectedOption = value; _selectedOption = value;
}); });
Navigator.of(context).pop(); // Close the dialog on selection Navigator.of(context)
}, .pop(); // Close the dialog on selection
), },
); ),
}).toList(), );
), }).toList(),
actions: <Widget>[
ElevatedButton(
child: Text('Submit'),
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('You selected: $_selectedOption'),
));
},
), ),
], actions: <Widget>[
); ElevatedButton(
}, child: Text('Submit'),
);} onPressed: () {
Navigator.of(context).pop(); // Close the dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('You selected: $_selectedOption'),
));
},
),
],
);
},
);
}
} }
// Remove a tab // Remove a tab
void _removeTab(int index) { void _removeTab(int index) {
if (_tabs[index] != 'Emails') { if (_tabs[index] != 'Emails') {
@ -119,7 +121,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
body: ListView.separated( body: ListView.separated(
itemCount: result.length, itemCount: result.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final SerializableMessage email = result[index]; final SerializableMessage email = result[index];
return ListTile( return ListTile(
title: Text(email.from, title: Text(email.from,
style: TextStyle(fontWeight: FontWeight.bold)), style: TextStyle(fontWeight: FontWeight.bold)),
@ -132,27 +134,24 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
// print('tapped'); // print('tapped');
// List<String> emailContent = // List<String> emailContent =
// await apiService.fetchEmailContent([email.id], email.list); // await apiService.fetchEmailContent([email.id], email.list);
//call the foldable //call the foldable
List<String> emailContent = // list of the html List<String> emailContent = // list of the html
await apiService.fetchEmailContent([email.id], email.list); await apiService
.fetchEmailContent([email.id], email.list);
// List<String> emailIds = email.messages; // List<String> emailIds = email.messages;
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) =>SonicEmailView( builder: (context) => SonicEmailView(
email: email, email: email, emailHTML: emailContent[0])),
emailHTML: emailContent[0])
),
); );
}, },
); );
}, },
separatorBuilder: (context, index) => Divider(), separatorBuilder: (context, index) => Divider(),
), ),
); );
} }
}, },
@ -170,7 +169,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
return Scaffold( return Scaffold(
backgroundColor: Theme.of(context).colorScheme.onPrimary, backgroundColor: Theme.of(context).colorScheme.onPrimary,
body: Padding( body: Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 0 , 20), padding: const EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Scaffold( child: Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
drawer: FolderDrawer( drawer: FolderDrawer(
@ -195,6 +194,12 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
ListTile(
leading: Icon(Icons.edit_note_sharp),
onTap: () {
OverlayService()
.showPersistentWidget(context);
}),
ListTile( ListTile(
leading: Icon(Icons.home), leading: Icon(Icons.home),
onTap: () { onTap: () {
@ -219,7 +224,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
child: Align( child: Align(
alignment: Alignment.bottomLeft, alignment: Alignment.bottomLeft,
child: IconButton( child: IconButton(
icon: Icon(Icons.close, color: Colors.white), icon:
Icon(Icons.close, color: Colors.white),
onPressed: () { onPressed: () {
setState(() { setState(() {
_isSidebarOpen = false; _isSidebarOpen = false;
@ -256,7 +262,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
), ),
onSubmitted: (value) { onSubmitted: (value) {
if (value.isNotEmpty) { if (value.isNotEmpty) {
_performSearch(value, _selectedOption); _performSearch(
value, _selectedOption);
} }
//this is the input box i mentioned //this is the input box i mentioned
// if (value == '') { // if (value == '') {
@ -314,8 +321,10 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
Text(entry.value), Text(entry.value),
if (entry.value != 'Emails') if (entry.value != 'Emails')
GestureDetector( GestureDetector(
onTap: () => _removeTab(entry.key), onTap: () =>
child: Icon(Icons.close, size: 16), _removeTab(entry.key),
child: Icon(Icons.close,
size: 16),
), ),
], ],
), ),
@ -333,14 +342,17 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
_emailPageKey.currentState!.isBackDisabled ? null: _emailPageKey.currentState _emailPageKey.currentState!.isBackDisabled
?.updatePagenation('back'); ? null
: _emailPageKey.currentState
?.updatePagenation('back');
}, },
child: Icon(Icons.navigate_before), child: Icon(Icons.navigate_before),
), ),
Builder( Builder(
builder: (context) { builder: (context) {
final emailState = _emailPageKey.currentState; final emailState =
_emailPageKey.currentState;
if (emailState == null) { if (emailState == null) {
// Schedule a rebuild once the state is available // Schedule a rebuild once the state is available
Future.microtask(() => setState(() {})); Future.microtask(() => setState(() {}));
@ -348,8 +360,10 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
} }
return ValueListenableBuilder<int>( return ValueListenableBuilder<int>(
valueListenable: emailState.currentPageNotifier, valueListenable:
builder: (context, value, _) => Text('$value'), emailState.currentPageNotifier,
builder: (context, value, _) =>
Text('$value'),
); );
}, },
), ),