side_menu_widget.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:fitness_dashboard_ui/const/constant.dart';
  2. import 'package:fitness_dashboard_ui/data/side_menu_data.dart';
  3. import 'package:flutter/material.dart';
  4. class SideMenuWidget extends StatefulWidget {
  5. const SideMenuWidget({super.key});
  6. @override
  7. State<SideMenuWidget> createState() => _SideMenuWidgetState();
  8. }
  9. class _SideMenuWidgetState extends State<SideMenuWidget> {
  10. int selectedIndex = 0;
  11. @override
  12. Widget build(BuildContext context) {
  13. final data = SideMenuData();
  14. return Container(
  15. padding: const EdgeInsets.symmetric(vertical: 80, horizontal: 20),
  16. color: const Color(0xFF171821),
  17. child: ListView.builder(
  18. itemCount: data.menu.length,
  19. itemBuilder: (context, index) => buildMenuEntry(data, index),
  20. ),
  21. );
  22. }
  23. Widget buildMenuEntry(SideMenuData data, int index) {
  24. final isSelected = selectedIndex == index;
  25. return Container(
  26. margin: const EdgeInsets.symmetric(vertical: 5),
  27. decoration: BoxDecoration(
  28. borderRadius: const BorderRadius.all(
  29. Radius.circular(6.0),
  30. ),
  31. color: isSelected ? selectionColor : Colors.transparent,
  32. ),
  33. child: InkWell(
  34. onTap: () => setState(() {
  35. selectedIndex = index;
  36. }),
  37. child: Row(
  38. children: [
  39. Padding(
  40. padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 7),
  41. child: Icon(
  42. data.menu[index].icon,
  43. color: isSelected ? Colors.black : Colors.grey,
  44. ),
  45. ),
  46. Text(
  47. data.menu[index].title,
  48. style: TextStyle(
  49. fontSize: 16,
  50. color: isSelected ? Colors.black : Colors.grey,
  51. fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
  52. ),
  53. )
  54. ],
  55. ),
  56. ),
  57. );
  58. }
  59. }