menu_buttons.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'dart:io' show Platform;
  2. import 'package:chicken_farm/stores/menu_store.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:go_router/go_router.dart';
  6. class MenuButtons extends ConsumerWidget {
  7. const MenuButtons({super.key});
  8. @override
  9. Widget build(BuildContext context, WidgetRef ref) {
  10. final visibleMenuItems = MenuStore.getVisibleMenuItems(ref);
  11. final screenWidth = MediaQuery.of(context).size.width;
  12. double buttonWidth = screenWidth * 0.8;
  13. buttonWidth = Platform.isAndroid
  14. ? buttonWidth
  15. : buttonWidth > 350
  16. ? 350
  17. : buttonWidth;
  18. return SingleChildScrollView(
  19. child: Center(
  20. child: Column(
  21. mainAxisAlignment: MainAxisAlignment.center,
  22. children: [
  23. for (var i = 0; i < visibleMenuItems.length; i++) ...[
  24. SizedBox(
  25. width: buttonWidth,
  26. height: 50,
  27. child: ElevatedButton.icon(
  28. onPressed: () {
  29. Future.delayed(const Duration(milliseconds: 100), () {
  30. if (context.mounted) {
  31. context.pushNamed(visibleMenuItems[i].routeName);
  32. }
  33. });
  34. },
  35. icon: visibleMenuItems[i].icon != null
  36. ? Icon(visibleMenuItems[i].icon)
  37. : const SizedBox.shrink(),
  38. label: Text(visibleMenuItems[i].name),
  39. ),
  40. ),
  41. if (i < visibleMenuItems.length - 1) ...[
  42. const SizedBox(height: 20.00),
  43. if (!Platform.isAndroid) ...[const SizedBox(height: 10.00)],
  44. ],
  45. ],
  46. ],
  47. ),
  48. ),
  49. );
  50. }
  51. }