start quesitonnaire
This commit is contained in:
@@ -1,26 +1,35 @@
|
||||
// needed for web horizontal scroll behavior
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fotodocumentation/main.dart';
|
||||
import 'package:fotodocumentation/pages/customer/customer_list_widget.dart';
|
||||
import 'package:fotodocumentation/pages/customer/customer_widget.dart';
|
||||
import 'package:fotodocumentation/pages/customer/picture_widget.dart';
|
||||
import 'package:fotodocumentation/pages/login/login_widget.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 GlobalKey<NavigatorState> bottomBarNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'bottombar');
|
||||
static final GlobalKey<NavigatorState> adminNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'admin');
|
||||
static final GlobalKey<NavigatorState> skillEditorNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'skillEditor');
|
||||
|
||||
static final String pathHome = "/home";
|
||||
static final String pathCustomer = "/customer";
|
||||
static final String pathPicture = "/picture";
|
||||
static final String pathLogin = "/login";
|
||||
static final String pathRoot = "/";
|
||||
|
||||
static final GoRouter router = createRouter(pathHome);
|
||||
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(
|
||||
@@ -28,40 +37,80 @@ class GlobalRouter {
|
||||
initialLocation: initialLocation,
|
||||
routes: <RouteBase>[
|
||||
GoRoute(
|
||||
path: "/",
|
||||
redirect: (_, __) => pathHome,
|
||||
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: pathLogin,
|
||||
builder: (BuildContext context, GoRouterState state) => const LoginWidget(),
|
||||
),
|
||||
GoRoute(
|
||||
path: pathHome,
|
||||
builder: (context, state) => CustomerListWidget(),
|
||||
path: pathFotoHome,
|
||||
builder: (context, state) => FotoCustomerListWidget(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "$pathCustomer/:customerId",
|
||||
path: "$pathFotoCustomer/:customerId",
|
||||
builder: (context, state) {
|
||||
var idStr = state.pathParameters['customerId'];
|
||||
var id = idStr == null ? null : int.tryParse(idStr);
|
||||
return CustomerWidget(customerId: id ?? -1);
|
||||
return FotoCustomerWidget(customerId: id ?? -1);
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "$pathPicture/:pictureId",
|
||||
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 PictureWidget(customerId: customerId ?? -1, pictureId: pictureId ?? -1);
|
||||
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();
|
||||
@@ -69,7 +118,18 @@ class GlobalRouter {
|
||||
LoginCredentials loginCredentials = DiContainer.get();
|
||||
|
||||
if (!loginCredentials.isLoggedIn) {
|
||||
return pathLogin;
|
||||
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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user