
Removes the dedicated `HomePage` and its associated model files. Configures `ReceptionPage` as the new default landing page after successful login and product form submission. Updates navigation and state management dependencies to direct users to the primary operational interface upon entry.
85 lines
2.3 KiB
Dart
85 lines
2.3 KiB
Dart
import 'package:barcode_scanner/router/go_router_builder.dart' hide $appRoutes;
|
|
import 'package:barcode_scanner/router/go_secure_router_builder.dart'
|
|
hide $appRoutes;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
final navigatorsRouteLocationsProvider = StateProvider<List<String>>(
|
|
(ref) => [],
|
|
);
|
|
|
|
final routerProvider = Provider<GoRouter>(
|
|
(ref) {
|
|
// ref.watch(authViewModelProvider);
|
|
|
|
return GoRouter(
|
|
debugLogDiagnostics: true,
|
|
routes: [...appRoutes, ...appSecureRoutes],
|
|
observers: [AppNavigatorObserver(ref: ref)],
|
|
navigatorKey: navigatorKey,
|
|
initialLocation: const ReceptionRoute().location,
|
|
errorBuilder: (context, state) {
|
|
// using a post frame callback to perform the navigation after
|
|
// the build frame has finished
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
const NotFoundRoute().go(context);
|
|
});
|
|
|
|
return const SizedBox.shrink();
|
|
},
|
|
);
|
|
},
|
|
dependencies: [
|
|
// authViewModelProvider,
|
|
],
|
|
);
|
|
|
|
class AppNavigatorObserver extends NavigatorObserver {
|
|
AppNavigatorObserver({required this.ref});
|
|
|
|
final Ref<GoRouter> ref;
|
|
|
|
@override
|
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
super.didPush(route, previousRoute);
|
|
_visitPage(route.settings.name);
|
|
}
|
|
|
|
@override
|
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
super.didPop(route, previousRoute);
|
|
_visitPage(previousRoute?.settings.name);
|
|
}
|
|
|
|
void _visitPage(String? location) {
|
|
if (location != null) {
|
|
if (location.startsWith('/')) {
|
|
Future.microtask(
|
|
() => ref.read(navigatorsRouteLocationsProvider.notifier).update((
|
|
state,
|
|
) {
|
|
final list = state..add(location);
|
|
return list.toList();
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
CustomTransitionPage buildPageWithDefaultTransition<T>({
|
|
required BuildContext context,
|
|
required GoRouterState state,
|
|
required Widget child,
|
|
}) {
|
|
return CustomTransitionPage<T>(
|
|
key: state.pageKey,
|
|
child: child,
|
|
transitionsBuilder:
|
|
(context, animation, secondaryAnimation, child) =>
|
|
FadeTransition(opacity: animation, child: child),
|
|
);
|
|
}
|