| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import 'package:chicken_farm/routes/app_routes.dart';
- import 'package:chicken_farm/stores/auth_store.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- class MenuButtons extends ConsumerWidget {
- const MenuButtons({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final authState = ref.watch(authStoreProvider);
- final authStore = ref.watch(authStoreProvider.notifier);
- final isSuperAdmin = authStore.isSuperAdmin();
- // 根据权限判断是否显示按钮
- final showCheckIn =
- isSuperAdmin ||
- (authState.permissions?.contains('device:inspection:checkin') ?? false);
- final showSampleTransfer =
- isSuperAdmin ||
- (authState.permissions?.contains('experiment:sample:query') ?? false);
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (showCheckIn)
- SizedBox(
- width: 200,
- height: 50,
- child: ElevatedButton.icon(
- onPressed: () {
- context.pushNamed(AppRouteNames.checkin);
- },
- icon: const Icon(Icons.check_circle_outline),
- label: const Text('点检签到'),
- ),
- ),
- const SizedBox(height: 20),
- if (showSampleTransfer)
- SizedBox(
- width: 200,
- height: 50,
- child: ElevatedButton.icon(
- onPressed: () {
- context.pushNamed(AppRouteNames.sample);
- },
- icon: const Icon(Icons.swap_horiz),
- label: const Text('样品查询'),
- ),
- ),
- ],
- );
- }
- }
|