refactor(directory): simplify floating action button and enhance menu structure
This commit is contained in:
parent
9c28dc05dd
commit
219815dd27
@ -25,7 +25,6 @@ class DirectoryView extends StatefulWidget {
|
||||
class _DirectoryViewState extends State<DirectoryView> {
|
||||
final DirectoryController controller = Get.find();
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
bool isFabExpanded = false;
|
||||
final PermissionController permissionController =
|
||||
Get.put(PermissionController());
|
||||
|
||||
@ -148,57 +147,11 @@ class _DirectoryViewState extends State<DirectoryView> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
floatingActionButton: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isFabExpanded) ...[
|
||||
Obx(() {
|
||||
if (permissionController
|
||||
.hasPermission(Permissions.directoryAdmin) ||
|
||||
permissionController
|
||||
.hasPermission(Permissions.directoryManager)) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: FloatingActionButton.extended(
|
||||
heroTag: 'manageBuckets',
|
||||
backgroundColor: Colors.grey[850],
|
||||
icon: const Icon(Icons.folder_open_outlined,
|
||||
color: Colors.white),
|
||||
label: const Text("Manage Buckets",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
onPressed: () {
|
||||
setState(() => isFabExpanded = false);
|
||||
_handleManageBuckets();
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: FloatingActionButton.extended(
|
||||
heroTag: 'createContact',
|
||||
backgroundColor: Colors.indigo,
|
||||
icon: const Icon(Icons.person_add_alt_1, color: Colors.white),
|
||||
label: const Text("Create Contact",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
onPressed: () {
|
||||
setState(() => isFabExpanded = false);
|
||||
_handleCreateContact();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
FloatingActionButton(
|
||||
heroTag: 'toggleFab',
|
||||
backgroundColor: Colors.red,
|
||||
onPressed: () => setState(() => isFabExpanded = !isFabExpanded),
|
||||
child: Icon(isFabExpanded ? Icons.close : Icons.add,
|
||||
color: Colors.white),
|
||||
),
|
||||
],
|
||||
floatingActionButton: FloatingActionButton(
|
||||
heroTag: 'createContact',
|
||||
backgroundColor: Colors.red,
|
||||
onPressed: _handleCreateContact,
|
||||
child: const Icon(Icons.person_add_alt_1, color: Colors.white),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
@ -312,28 +265,89 @@ class _DirectoryViewState extends State<DirectoryView> {
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem<int>(
|
||||
value: 0,
|
||||
enabled: false,
|
||||
child: Obx(() => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
MyText.bodySmall('Show Inactive',
|
||||
fontWeight: 600),
|
||||
Switch.adaptive(
|
||||
value: !controller.isActive.value,
|
||||
activeColor: Colors.indigo,
|
||||
onChanged: (val) {
|
||||
controller.isActive.value = !val;
|
||||
controller.fetchContacts(active: !val);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
itemBuilder: (context) {
|
||||
List<PopupMenuEntry<int>> menuItems = [];
|
||||
|
||||
// Section: Actions
|
||||
if (permissionController
|
||||
.hasPermission(Permissions.directoryAdmin) ||
|
||||
permissionController
|
||||
.hasPermission(Permissions.directoryManager)) {
|
||||
menuItems.add(
|
||||
const PopupMenuItem<int>(
|
||||
enabled: false,
|
||||
height: 30,
|
||||
child: Text(
|
||||
"Actions",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
menuItems.add(
|
||||
PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.label_outline,
|
||||
size: 20, color: Colors.black87),
|
||||
SizedBox(width: 10),
|
||||
Expanded(child: Text("Manage Buckets")),
|
||||
Icon(Icons.chevron_right,
|
||||
size: 20, color: Colors.red),
|
||||
],
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
Future.delayed(Duration.zero, () {
|
||||
_handleManageBuckets();
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Section: Preferences
|
||||
menuItems.add(
|
||||
const PopupMenuItem<int>(
|
||||
enabled: false,
|
||||
height: 30,
|
||||
child: Text(
|
||||
"Preferences",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
menuItems.add(
|
||||
PopupMenuItem<int>(
|
||||
value: 0,
|
||||
enabled: false,
|
||||
child: Obx(() => Row(
|
||||
children: [
|
||||
const Icon(Icons.visibility_off_outlined,
|
||||
size: 20, color: Colors.black87),
|
||||
const SizedBox(width: 10),
|
||||
const Expanded(child: Text('Show Inactive')),
|
||||
Switch.adaptive(
|
||||
value: !controller.isActive.value,
|
||||
activeColor: Colors.indigo,
|
||||
onChanged: (val) {
|
||||
controller.isActive.value = !val;
|
||||
controller.fetchContacts(active: !val);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
);
|
||||
|
||||
return menuItems;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user