WIP: folders actions #5
@ -16,6 +16,7 @@ class FolderDrawer extends StatefulWidget {
|
|||||||
|
|
||||||
class _FolderDrawerState extends State<FolderDrawer> {
|
class _FolderDrawerState extends State<FolderDrawer> {
|
||||||
List<String> folders = [];
|
List<String> folders = [];
|
||||||
|
final TextEditingController _renameController = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -48,7 +49,7 @@ class _FolderDrawerState extends State<FolderDrawer> {
|
|||||||
icon: Icon(Icons.more_vert),
|
icon: Icon(Icons.more_vert),
|
||||||
onPressed: () => {
|
onPressed: () => {
|
||||||
///show options
|
///show options
|
||||||
_showOptions(context)
|
_showOptions(context, folder)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@ -65,7 +66,7 @@ class _FolderDrawerState extends State<FolderDrawer> {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return NewMailbox(apiService: widget.apiService);
|
return NewMailbox(apiService: widget.apiService);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// Navigator.of(context).pop();
|
// Navigator.of(context).pop();
|
||||||
@ -83,39 +84,74 @@ class _FolderDrawerState extends State<FolderDrawer> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
void _showOptions(BuildContext context) async {
|
|
||||||
final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
|
|
||||||
|
|
||||||
await showMenu<String>(
|
|
||||||
context: context,
|
|
||||||
position: RelativeRect.fromLTRB(100, 100, overlay.size.width, overlay.size.height),
|
|
||||||
items: <PopupMenuEntry<String>>[
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: 'Rename',
|
|
||||||
child: Text('Rename Folder'),
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: 'Delete',
|
|
||||||
child: Text('Delete Folder'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).then((value) {
|
|
||||||
// Handle the action based on the selected menu item
|
|
||||||
if (value == 'Rename') {
|
|
||||||
// Logic for renaming the folder
|
|
||||||
print('Rename folder');
|
|
||||||
} else if (value == 'Delete') {
|
|
||||||
// Logic for deleting the folder
|
|
||||||
print('Delete folder');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Future<bool> _renameDialog(String oldFolder) async {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text("Rename Mailbox"),
|
||||||
|
content: TextField(
|
||||||
|
controller: _renameController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: "New Name",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
String newfolderName = _renameController.text;
|
||||||
|
if (newfolderName.isNotEmpty) {
|
||||||
|
//make an and to make sure there's two folders with the same name
|
||||||
|
ApiService().renameFolder(oldFolder, newfolderName);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text("Rename"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showOptions(BuildContext context, String folderName) async {
|
||||||
|
final RenderBox overlay =
|
||||||
|
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||||
|
print(folderName);
|
||||||
|
await showMenu<String>(
|
||||||
|
context: context,
|
||||||
|
position: RelativeRect.fromLTRB(
|
||||||
|
100, 100, overlay.size.width, overlay.size.height),
|
||||||
|
items: <PopupMenuEntry<String>>[
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'Rename',
|
||||||
|
child: Text('Rename Folder'),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'Delete',
|
||||||
|
child: Text('Delete Folder'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).then((value) {
|
||||||
|
// Handle the action based on the selected menu item
|
||||||
|
if (value == 'Rename') {
|
||||||
|
// Logic for renaming the folder
|
||||||
|
print('Rename folder $folderName');
|
||||||
|
_renameDialog(folderName);
|
||||||
|
} else if (value == 'Delete') {
|
||||||
|
// Logic for deleting the folder
|
||||||
|
print("Deleting $folderName");
|
||||||
|
ApiService().deleteFolder(folderName);
|
||||||
|
print('Deleted folder');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NewMailbox extends StatelessWidget {
|
class NewMailbox extends StatelessWidget {
|
||||||
final ApiService apiService;
|
final ApiService apiService;
|
||||||
// final Function(String) onFolderCreated;
|
|
||||||
final TextEditingController _textFieldController = TextEditingController();
|
final TextEditingController _textFieldController = TextEditingController();
|
||||||
|
|
||||||
NewMailbox({required this.apiService});
|
NewMailbox({required this.apiService});
|
||||||
@ -127,7 +163,7 @@ class NewMailbox extends StatelessWidget {
|
|||||||
content: TextField(
|
content: TextField(
|
||||||
controller: _textFieldController,
|
controller: _textFieldController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
hintText: "EPIC FOLDER", // Your custom hint text here
|
hintText: "New Folder",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
@ -138,9 +174,7 @@ class NewMailbox extends StatelessWidget {
|
|||||||
|
|
||||||
if (folderName.isNotEmpty) {
|
if (folderName.isNotEmpty) {
|
||||||
apiService.createFolder(folderName);
|
apiService.createFolder(folderName);
|
||||||
// onFolderCreated(folderName);
|
|
||||||
}
|
}
|
||||||
// apiService.createFolder(_textFieldController.text);
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: const Text("Approve"),
|
child: const Text("Approve"),
|
||||||
|
Loading…
Reference in New Issue
Block a user