178 lines
5.0 KiB
Dart
178 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../l10n/app_localizations.dart';
|
|
import '../utils/navigation.dart';
|
|
import '../viewmodels/admin_pin_view_model.dart';
|
|
|
|
class AdminScreenView extends StatelessWidget {
|
|
const AdminScreenView({super.key});
|
|
|
|
void _leave(BuildContext context) {
|
|
final adminPinViewModel = context.read<AdminPinViewModel>();
|
|
context.popOrGo('/bar');
|
|
adminPinViewModel.lock();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context);
|
|
|
|
return PopScope(
|
|
onPopInvokedWithResult: (didPop, result) {
|
|
if (didPop) context.read<AdminPinViewModel>().lock();
|
|
},
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
onPressed: () => _leave(context),
|
|
icon: const Icon(Icons.arrow_back),
|
|
),
|
|
title: Text(l10n.admin),
|
|
actions: [
|
|
IconButton(
|
|
tooltip: l10n.logout,
|
|
onPressed: () {
|
|
final adminPinViewModel = context.read<AdminPinViewModel>();
|
|
context.go('/bar');
|
|
adminPinViewModel.lock();
|
|
},
|
|
icon: const Icon(Icons.logout),
|
|
),
|
|
],
|
|
),
|
|
body: ListView(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
children: [
|
|
_AdminSection(
|
|
title: l10n.adminTools,
|
|
children: [
|
|
_AdminTile(
|
|
icon: Icons.inventory_2_outlined,
|
|
title: l10n.products,
|
|
subtitle: l10n.manageProducts,
|
|
onTap: () => context.push('/products'),
|
|
),
|
|
_AdminTile(
|
|
icon: Icons.file_upload_outlined,
|
|
title: l10n.importData,
|
|
subtitle: l10n.importNamesDescription,
|
|
onTap: () => context.push('/admin/import'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AdminSection extends StatelessWidget {
|
|
final String title;
|
|
final List<Widget> children;
|
|
|
|
const _AdminSection({required this.title, required this.children});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title.toUpperCase(),
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 0.5,
|
|
color: scheme.onSurface.withValues(alpha: 0.5),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: scheme.onSurface.withValues(alpha: 0.04),
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(
|
|
color: scheme.onSurface.withValues(alpha: 0.06),
|
|
),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(children: children),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AdminTile extends StatelessWidget {
|
|
final IconData icon;
|
|
final String title;
|
|
final String? subtitle;
|
|
final VoidCallback? onTap;
|
|
|
|
const _AdminTile({
|
|
required this.icon,
|
|
required this.title,
|
|
this.subtitle,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
|
|
return Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
icon,
|
|
size: 22,
|
|
color: scheme.onSurface.withValues(alpha: 0.7),
|
|
),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
color: scheme.onSurface,
|
|
),
|
|
),
|
|
if (subtitle != null)
|
|
Text(
|
|
subtitle!,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: scheme.onSurface.withValues(alpha: 0.5),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (onTap != null)
|
|
Icon(
|
|
Icons.chevron_right_rounded,
|
|
color: scheme.onSurface.withValues(alpha: 0.3),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|