139 lines
5.5 KiB
Dart
139 lines
5.5 KiB
Dart
// needed for web horizontal scroll behavior
|
|
import 'package:flutter/material.dart';
|
|
import 'package:fotodocumentation/main.dart';
|
|
import 'package:fotodocumentation/pages/foto/customer/foto_customer_list_widget.dart';
|
|
import 'package:fotodocumentation/pages/foto/customer/foto_customer_widget.dart';
|
|
import 'package:fotodocumentation/pages/foto/customer/foto_picture_widget.dart';
|
|
import 'package:fotodocumentation/pages/foto/login/foto_login_widget.dart';
|
|
import 'package:fotodocumentation/pages/questionnaire/customer/questionnaire_customer_list_widget.dart';
|
|
import 'package:fotodocumentation/pages/questionnaire/customer/questionnaire_customer_widget.dart';
|
|
import 'package:fotodocumentation/pages/questionnaire/login/questionnaire_login_widget.dart';
|
|
import 'package:fotodocumentation/utils/di_container.dart';
|
|
import 'package:fotodocumentation/utils/login_credentials.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class GlobalRouter {
|
|
static final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root');
|
|
|
|
static final String pathRoot = "/";
|
|
|
|
static final String pathFoto = "/foto";
|
|
static final String pathQuestionnaire = "/fragenbogen";
|
|
|
|
static final String pathFotoHome = "$pathFoto/home";
|
|
static final String pathFotoCustomer = "$pathFoto/customer";
|
|
static final String pathFotoPicture = "$pathFoto/picture";
|
|
static final String pathFotoLogin = "$pathFoto/login";
|
|
|
|
static final String pathQuestionnaireHome = "$pathQuestionnaire/home";
|
|
static final String pathQuestionnaireCustomer = "customer";
|
|
static final String pathQuestionnaireLogin = "$pathQuestionnaire/login";
|
|
|
|
static final GoRouter router = createRouter(pathRoot);
|
|
|
|
static GoRouter createRouter(String initialLocation) {
|
|
return GoRouter(
|
|
navigatorKey: rootNavigatorKey,
|
|
initialLocation: initialLocation,
|
|
routes: <RouteBase>[
|
|
GoRoute(
|
|
path: "/",
|
|
redirect: (_, __) {//nvlev4YnTi
|
|
logger.t("uri / redirect to $pathFotoHome");
|
|
return pathFotoHome;
|
|
}),
|
|
GoRoute(
|
|
path: pathFoto,
|
|
redirect: (_, __) {
|
|
logger.t("uri $pathFoto redirect to $pathFotoHome");
|
|
return pathFotoHome;
|
|
}),
|
|
GoRoute(
|
|
path: pathFotoLogin,
|
|
builder: (_, __) {
|
|
logger.t("uri $pathFotoLogin show foto login");
|
|
return const FotoLoginWidget();
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: pathFotoHome,
|
|
builder: (context, state) => FotoCustomerListWidget(),
|
|
routes: [
|
|
GoRoute(
|
|
path: "$pathFotoCustomer/:customerId",
|
|
builder: (context, state) {
|
|
var idStr = state.pathParameters['customerId'];
|
|
var id = idStr == null ? null : int.tryParse(idStr);
|
|
return FotoCustomerWidget(customerId: id ?? -1);
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: "$pathFotoPicture/:pictureId",
|
|
builder: (context, state) {
|
|
var customerIdStr = state.pathParameters['customerId'];
|
|
var customerId = customerIdStr == null ? null : int.tryParse(customerIdStr);
|
|
|
|
var pictureIdStr = state.pathParameters['pictureId'];
|
|
var pictureId = pictureIdStr == null ? null : int.tryParse(pictureIdStr);
|
|
return FotoPictureWidget(customerId: customerId ?? -1, pictureId: pictureId ?? -1);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
GoRoute(
|
|
path: pathQuestionnaire,
|
|
redirect: (_, __) {
|
|
logger.t("uri $pathQuestionnaire redirect to $pathQuestionnaireHome");
|
|
return pathQuestionnaireHome;
|
|
}),
|
|
GoRoute(
|
|
path: pathQuestionnaireLogin,
|
|
builder: (_, __) {
|
|
logger.t("uri $pathQuestionnaireLogin show questionnaire login");
|
|
return const QuestionaireLoginWidget();
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: pathQuestionnaireHome,
|
|
builder: (context, state) => QuestionaireCustomerListWidget(),
|
|
routes: [
|
|
GoRoute(
|
|
path: "$pathQuestionnaireCustomer/:customerId",
|
|
builder: (context, state) {
|
|
var uriStr = state.uri.toString();
|
|
logger.t("uri $uriStr show questionnaire");
|
|
var idStr = state.pathParameters['customerId'];
|
|
var id = idStr == null ? null : int.tryParse(idStr);
|
|
return QuestionaireCustomerWidget(customerId: id ?? -1);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
redirect: (context, state) {
|
|
var uriStr = state.uri.toString();
|
|
logger.t("uri $uriStr");
|
|
LoginCredentials loginCredentials = DiContainer.get();
|
|
|
|
if (!loginCredentials.isLoggedIn) {
|
|
if (uriStr != '/') {
|
|
if (uriStr.startsWith(pathFoto) && !uriStr.startsWith(pathFotoLogin)) {
|
|
var url = '$pathFotoLogin?redirect=${Uri.encodeComponent(uriStr)}';
|
|
logger.t("foto redirect to $url");
|
|
return url;
|
|
}
|
|
if (uriStr.startsWith(pathQuestionnaire) && !uriStr.startsWith(pathQuestionnaireLogin)) {
|
|
var url = '$pathQuestionnaireLogin?redirect=${Uri.encodeComponent(uriStr)}';
|
|
logger.t("questionnaire redirect to $url");
|
|
return url;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
}
|
|
}
|