feat: move history to admin page

This commit is contained in:
2026-08-07 05:18:51 +02:00
parent 799c1c4045
commit 66a4edacb7
3 changed files with 96 additions and 39 deletions
+67 -33
View File
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
@@ -19,6 +20,67 @@ import '../utils/app_update_util.dart';
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
String? _redirectApp({
required PinLockViewModel pinLockViewModel,
required AdminPinViewModel adminPinViewModel,
required GoRouterState state,
}) {
if (!pinLockViewModel.hasLoaded || !adminPinViewModel.hasLoaded) {
return null;
}
final location = state.uri.path;
final goingToLock = location == '/lock';
final goingToAdminLock = location == '/admin/lock';
final mustBeOnLock = _mustBeOnLock(pinLockViewModel);
if (mustBeOnLock && !goingToLock) return '/lock';
if (!mustBeOnLock && goingToLock) return '/bar';
final isAdminArea = _isAdminArea(location);
final isDebugShortcutArea = _isDebugShortcutArea(location);
if (isAdminArea &&
!isDebugShortcutArea &&
!goingToAdminLock &&
!adminPinViewModel.isUnlocked) {
return '/admin/lock';
}
if (goingToAdminLock && adminPinViewModel.isUnlocked) return '/admin';
return null;
}
bool _mustBeOnLock(PinLockViewModel pinLockViewModel) {
final needsPinSetup =
!pinLockViewModel.isPinSet && pinLockViewModel.pinRequired;
final isLocked =
pinLockViewModel.isPinSet &&
!pinLockViewModel.isUnlocked &&
pinLockViewModel.pinRequired;
return needsPinSetup || isLocked;
}
bool _isAdminArea(String location) {
return location == '/admin' ||
location.startsWith('/admin/') ||
location == '/products' ||
location.startsWith('/products/') ||
location == '/history' ||
location.startsWith('/history/');
}
bool _isDebugShortcutArea(String location) {
if (!kDebugMode) return false;
return location == '/products' ||
location.startsWith('/products/') ||
location == '/history' ||
location.startsWith('/history/');
}
GoRouter createAppRouter(
PinLockViewModel pinLockViewModel, {
required AdminPinViewModel adminPinViewModel,
@@ -27,39 +89,11 @@ GoRouter createAppRouter(
initialLocation: '/bar',
observers: [routeObserver, SentryNavigatorObserver()],
refreshListenable: Listenable.merge([pinLockViewModel, adminPinViewModel]),
redirect: (context, state) {
if (!pinLockViewModel.hasLoaded || !adminPinViewModel.hasLoaded) {
return null;
}
final needsPinSetup =
!pinLockViewModel.isPinSet && pinLockViewModel.pinRequired;
final isLocked =
pinLockViewModel.isPinSet &&
!pinLockViewModel.isUnlocked &&
pinLockViewModel.pinRequired;
final mustBeOnLock = needsPinSetup || isLocked;
final location = state.uri.path;
final goingToLock = location == '/lock';
final goingToAdminLock = location == '/admin/lock';
final isAdminArea =
location == '/admin' ||
location.startsWith('/admin/') ||
location == '/products' ||
location.startsWith('/products/');
if (mustBeOnLock && !goingToLock) return '/lock';
if (!mustBeOnLock && goingToLock) return '/bar';
if (isAdminArea && !goingToAdminLock && !adminPinViewModel.isUnlocked) {
return '/admin/lock';
}
if (goingToAdminLock && adminPinViewModel.isUnlocked) return '/admin';
return null;
},
redirect: (_, state) => _redirectApp(
pinLockViewModel: pinLockViewModel,
adminPinViewModel: adminPinViewModel,
state: state,
),
routes: [
GoRoute(path: '/', redirect: (context, state) => '/bar'),
GoRoute(
+6
View File
@@ -54,6 +54,12 @@ class AdminScreenView extends StatelessWidget {
subtitle: l10n.manageProducts,
onTap: () => context.push('/products'),
),
_AdminTile(
icon: Icons.history_rounded,
title: l10n.tabHistory,
subtitle: l10n.closedTabs,
onTap: () => context.push('/history'),
),
_AdminTile(
icon: Icons.file_upload_outlined,
title: l10n.importData,
+23 -6
View File
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:kooltab2/viewmodels/admin_pin_view_model.dart';
@@ -57,12 +58,28 @@ class _BarScreenViewState extends State<BarScreenView> {
onPressed: () => context.push('/admin'),
icon: const Icon(Icons.admin_panel_settings_outlined),
),
const SizedBox(width: 6),
IconButton(
tooltip: l10n.tabHistory,
onPressed: () => context.push('/history'),
icon: const Icon(Icons.history_rounded),
),
if (kDebugMode) ...[
const SizedBox(width: 6),
IconButton(
tooltip: l10n.manageProducts,
style: IconButton.styleFrom(
backgroundColor: Colors.yellow,
foregroundColor: Colors.black,
),
onPressed: () => context.push('/products'),
icon: const Icon(Icons.inventory_2_outlined),
),
const SizedBox(width: 6),
IconButton(
tooltip: l10n.tabHistory,
style: IconButton.styleFrom(
backgroundColor: Colors.yellow,
foregroundColor: Colors.black,
),
onPressed: () => context.push('/history'),
icon: const Icon(Icons.history_rounded),
),
],
const SizedBox(width: 6),
IconButton(
tooltip: l10n.refresh,