menu_buttons.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:chicken_farm/routes/app_routes.dart';
  2. import 'package:chicken_farm/stores/auth_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 authState = ref.watch(authStoreProvider);
  11. final authStore = ref.watch(authStoreProvider.notifier);
  12. final isSuperAdmin = authStore.isSuperAdmin();
  13. // 根据权限判断是否显示按钮
  14. final showCheckIn =
  15. isSuperAdmin || (authState.permissions?.contains('checkin') ?? false);
  16. final showSampleTransfer =
  17. isSuperAdmin ||
  18. (authState.permissions?.contains('sample_transfer') ?? false);
  19. return Column(
  20. mainAxisAlignment: MainAxisAlignment.center,
  21. children: [
  22. if (showCheckIn)
  23. SizedBox(
  24. width: 200,
  25. height: 50,
  26. child: ElevatedButton.icon(
  27. onPressed: () {
  28. context.pushNamed(AppRoutePaths.checkin);
  29. },
  30. icon: const Icon(Icons.check_circle_outline),
  31. label: const Text('点检签到'),
  32. ),
  33. ),
  34. const SizedBox(height: 20),
  35. if (showSampleTransfer)
  36. SizedBox(
  37. width: 200,
  38. height: 50,
  39. child: ElevatedButton.icon(
  40. onPressed: () {
  41. context.pushNamed(AppRoutePaths.sampleTransfer);
  42. },
  43. icon: const Icon(Icons.swap_horiz),
  44. label: const Text('样品流转'),
  45. ),
  46. ),
  47. ],
  48. );
  49. }
  50. }