menu_buttons.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 ||
  16. (authState.permissions?.contains('device:inspection:checkin') ?? false);
  17. final showSampleTransfer =
  18. isSuperAdmin ||
  19. (authState.permissions?.contains('experiment:sample:query') ?? false);
  20. return Column(
  21. mainAxisAlignment: MainAxisAlignment.center,
  22. children: [
  23. if (showCheckIn)
  24. SizedBox(
  25. width: 200,
  26. height: 50,
  27. child: ElevatedButton.icon(
  28. onPressed: () {
  29. context.pushNamed(AppRouteNames.checkin);
  30. },
  31. icon: const Icon(Icons.check_circle_outline),
  32. label: const Text('点检签到'),
  33. ),
  34. ),
  35. const SizedBox(height: 20),
  36. if (showSampleTransfer)
  37. SizedBox(
  38. width: 200,
  39. height: 50,
  40. child: ElevatedButton.icon(
  41. onPressed: () {
  42. context.pushNamed(AppRouteNames.sample);
  43. },
  44. icon: const Icon(Icons.swap_horiz),
  45. label: const Text('样品查询'),
  46. ),
  47. ),
  48. ],
  49. );
  50. }
  51. }