| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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('checkin') ?? false);
- final showSampleTransfer =
- isSuperAdmin ||
- (authState.permissions?.contains('sample_transfer') ?? false);
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (showCheckIn)
- SizedBox(
- width: 200,
- height: 50,
- child: ElevatedButton.icon(
- onPressed: () {
- context.pushNamed(AppRoutePaths.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(AppRoutePaths.sampleTransfer);
- },
- icon: const Icon(Icons.swap_horiz),
- label: const Text('样品流转'),
- ),
- ),
- ],
- );
- }
- }
|