feat: add pin lock / fix performance on history view
This commit is contained in:
+10
-10
@@ -1,23 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:kooltab2/theme.dart';
|
||||
|
||||
import 'router.dart';
|
||||
|
||||
class KoolTabApp extends StatelessWidget {
|
||||
const KoolTabApp({super.key});
|
||||
const KoolTabApp({
|
||||
super.key,
|
||||
required this.router,
|
||||
});
|
||||
|
||||
final GoRouter router;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
title: 'KoolTab',
|
||||
debugShowCheckedModeBanner: false,
|
||||
routerConfig: appRouter,
|
||||
// theme: ThemeData(
|
||||
// useMaterial3: false,
|
||||
// colorSchemeSeed: Colors.blueAccent,
|
||||
// brightness: Brightness.light,
|
||||
// ),
|
||||
theme: darkTheme
|
||||
routerConfig: router,
|
||||
// theme: lightTheme,
|
||||
theme: darkTheme,
|
||||
);
|
||||
}
|
||||
}
|
||||
+58
-31
@@ -1,45 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../viewmodels/pin_lock_view_model.dart';
|
||||
import '../views/bar_screen_view.dart';
|
||||
import '../views/history_screen_view.dart';
|
||||
import '../views/pin_lock_view.dart';
|
||||
import '../views/product_form_view.dart';
|
||||
import '../views/product_list_view.dart';
|
||||
|
||||
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
|
||||
|
||||
final appRouter = GoRouter(
|
||||
initialLocation: '/bar',
|
||||
observers: [
|
||||
routeObserver,
|
||||
],
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/bar',
|
||||
builder: (context, state) => const BarScreenView(),
|
||||
),
|
||||
GoRouter createAppRouter(PinLockViewModel pinLockViewModel) {
|
||||
return GoRouter(
|
||||
initialLocation: '/bar',
|
||||
observers: [routeObserver],
|
||||
refreshListenable: pinLockViewModel,
|
||||
redirect: (context, state) {
|
||||
if (!pinLockViewModel.hasLoaded) return null;
|
||||
|
||||
GoRoute(
|
||||
path: '/products',
|
||||
builder: (context, state) => const ProductListView(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'new',
|
||||
builder: (context, state) => const ProductFormView(),
|
||||
),
|
||||
GoRoute(
|
||||
path: ':id/edit',
|
||||
builder: (context, state) {
|
||||
final productId = state.pathParameters['id']!;
|
||||
final needsSetup = !pinLockViewModel.isPinSet;
|
||||
final isLocked =
|
||||
pinLockViewModel.isPinSet && !pinLockViewModel.isUnlocked;
|
||||
final mustBeOnLock = needsSetup || isLocked;
|
||||
|
||||
return ProductFormView(productId: productId);
|
||||
final goingToLock = state.matchedLocation == '/lock';
|
||||
|
||||
if (mustBeOnLock && !goingToLock) return '/lock';
|
||||
if (!mustBeOnLock && goingToLock) return '/bar';
|
||||
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/lock',
|
||||
builder: (context, state) => PinEntryView(
|
||||
mode: pinLockViewModel.isPinSet
|
||||
? PinEntryMode.unlock
|
||||
: PinEntryMode.create,
|
||||
onSuccess: () {
|
||||
context.go("/bar");
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/history',
|
||||
builder: (context, state) => const HistoryScreenView(),
|
||||
),
|
||||
],
|
||||
);
|
||||
),
|
||||
|
||||
GoRoute(path: '/bar', builder: (context, state) => const BarScreenView()),
|
||||
|
||||
GoRoute(
|
||||
path: '/products',
|
||||
builder: (context, state) => const ProductListView(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'new',
|
||||
builder: (context, state) => const ProductFormView(),
|
||||
),
|
||||
GoRoute(
|
||||
path: ':id/edit',
|
||||
builder: (context, state) {
|
||||
final productId = state.pathParameters['id']!;
|
||||
|
||||
return ProductFormView(productId: productId);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/history',
|
||||
builder: (context, state) => const HistoryScreenView(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user