routes.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import 'dart:developer';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:hive_flutter/hive_flutter.dart';
  6. import 'package:jiffy/jiffy.dart';
  7. import 'package:tp5/auth/auth.dart';
  8. import 'package:tp5/core/basic_page.dart';
  9. import 'package:tp5/core/utils.dart';
  10. import 'package:tp5/flightslist/flightslist_page.dart';
  11. import 'package:tp5/fltinfo/view/dutyinfo_page.dart';
  12. import 'package:tp5/fltinfo/view/fltinfo_page.dart';
  13. import 'package:tp5/ftl/view/ftl_page.dart';
  14. import 'package:tp5/lido/view/lido_form.dart';
  15. import 'package:tp5/lido/view/lidolist_page.dart';
  16. import 'package:tp5/lido/view/lidoofp_page.dart';
  17. import 'package:tp5/onboarding/onboarding.dart';
  18. import 'package:tp5/pdf/pdf_page.dart';
  19. import 'package:tp5/roster/view/crewlink_form.dart';
  20. import 'package:tp5/roster/view/crewlist_page.dart';
  21. import 'package:tp5/roster/view/roster_page.dart';
  22. import 'package:tp5/rosters/rosters_page.dart';
  23. final routeProvider = Provider<RouterConfig<Object>?>((ref) {
  24. return _routes;
  25. });
  26. final _routes = GoRouter(
  27. debugLogDiagnostics: false,
  28. redirect: (_, s) {
  29. log("${s.fullPath} | ${s.extra.runtimeType.toString()}", name: "routes");
  30. if (DateTime.now().isAfter(DateTime(2024, 11, 1))) {
  31. return "/expired";
  32. }
  33. return null;
  34. },
  35. // initialLocation: '/test',
  36. initialLocation: '/crewlink/roster',
  37. routes: [
  38. GoRoute(
  39. path: '/test',
  40. builder: (context, state) => BasicPage(
  41. appBar: AppBar(
  42. automaticallyImplyLeading: false,
  43. title: const Text("TAR Pilot v5"),
  44. ),
  45. drawer: ListView(),
  46. body: Column(
  47. children: [
  48. Text("${Jiffy.parseFromList([
  49. 2024,
  50. 9,
  51. 1,
  52. 20,
  53. 0
  54. ], isUtc: true).setTz(ap: "TUN").toUtc().dateTime}"),
  55. Text(DTInterval.fromHm(
  56. apartir:
  57. Jiffy.parseFromList([2024, 9, 1, 1, 1], isUtc: true)
  58. .setTz(ap: "TUN"),
  59. h: 2,
  60. m: 0,
  61. duration: const Duration(hours: 2, minutes: 59),
  62. ap: "TUN")
  63. .start
  64. .dateTime
  65. .toIso8601String())
  66. ],
  67. ),
  68. ),
  69. ),
  70. GoRoute(
  71. path: '/expired',
  72. builder: (context, state) => BasicPage(
  73. appBar: AppBar(
  74. automaticallyImplyLeading: false,
  75. title: const Text("TAR Pilot v5"),
  76. ),
  77. drawer: ListView(),
  78. body: const Text("App is Expired please Update")),
  79. ),
  80. GoRoute(
  81. path: '/login',
  82. builder: (context, state) => const LoginPage(),
  83. ),
  84. GoRoute(
  85. path: '/verification',
  86. builder: (context, state) {
  87. final params = state.extra as VerificationPageParams?;
  88. if (params == null) {
  89. throw 'Missing `VerificationPageParams` object';
  90. }
  91. return VerificationPage(params: params);
  92. },
  93. ),
  94. GoRoute(
  95. path: '/pdf',
  96. builder: (context, state) {
  97. final params = state.extra as PdfPageParams;
  98. return PdfPage(params: params);
  99. },
  100. ),
  101. GoRoute(
  102. path: '/rosters',
  103. builder: (context, state) {
  104. return const RostersPage();
  105. },
  106. ),
  107. GoRoute(
  108. path: '/flightslist',
  109. builder: (context, state) {
  110. return const FlightslistPage();
  111. },
  112. ),
  113. GoRoute(
  114. path: '/ftl',
  115. builder: (context, state) {
  116. final params = (state.extra as FtlPageParams?) ?? const FtlPageParams();
  117. return FtlPage(params: params);
  118. },
  119. ),
  120. GoRoute(
  121. path: '/fltinfo',
  122. builder: (context, state) {
  123. final params = (state.extra as FltinfoParams?) ?? const FltinfoParams();
  124. return FltinfoPage(params: params);
  125. },
  126. ),
  127. GoRoute(
  128. path: '/dutyinfo',
  129. builder: (context, state) {
  130. final params =
  131. (state.extra as DutyinfoParams?) ?? const DutyinfoParams();
  132. return DutyinfoPage(params: params);
  133. },
  134. ),
  135. GoRoute(
  136. path: "/lido",
  137. redirect: (_, state) {
  138. // log(state.fullPath.toString());
  139. if
  140. // (["/crewlink/roster"].contains(state.uri.toString())&&
  141. (state.fullPath != "/lido/settings" &&
  142. (((Hive.box("profile").get("lido_user") ?? "") == "") ||
  143. ((Hive.box("profile").get("lido_pass") ?? "") == ""))) {
  144. return "/lido/settings";
  145. }
  146. return null;
  147. },
  148. routes: [
  149. GoRoute(
  150. name: "lido.list",
  151. path: 'list',
  152. builder: (context, state) {
  153. final params = (state.extra as LidolistPageParams?) ??
  154. const LidolistPageParams();
  155. return LidolistPage(params: params);
  156. }),
  157. GoRoute(
  158. name: "lido.ofp",
  159. path: 'ofp',
  160. builder: (context, state) {
  161. final params = (state.extra as LidoofpPageParams?) ??
  162. const LidoofpPageParams();
  163. return LidoofpPage(params: params);
  164. }),
  165. GoRoute(
  166. path: 'settings', builder: (context, state) => const LidoForm()),
  167. ]),
  168. GoRoute(
  169. path: "/crewlink",
  170. redirect: (_, state) {
  171. // log(state.fullPath.toString());
  172. if
  173. // (["/crewlink/roster"].contains(state.uri.toString())&&
  174. (state.fullPath != "/crewlink/settings" &&
  175. (((Hive.box("profile").get("crewlink_user") ?? "") == "") ||
  176. ((Hive.box("profile").get("crewlink_pass") ?? "") ==
  177. ""))) {
  178. return "/crewlink/settings";
  179. }
  180. return null;
  181. },
  182. routes: [
  183. GoRoute(
  184. name: "crewlink.roster",
  185. path: 'roster',
  186. builder: (context, state) {
  187. final params = (state.extra as RosterPageParams?) ??
  188. const RosterPageParams();
  189. return RosterPage(
  190. params: RosterPageParams(
  191. datestart: params.datestart ??
  192. Jiffy.now()
  193. .toUtc()
  194. .startOf(Unit.month)
  195. // .subtract(days: 30)
  196. .format(pattern: "ddMMMyy"),
  197. dateend: params.dateend ??
  198. Jiffy.now()
  199. .toUtc()
  200. .endOf(Unit.month)
  201. .format(pattern: "ddMMMyy"),
  202. crewlinkuser: params.crewlinkuser ??
  203. Hive.box("profile").get("crewlink_user") ??
  204. "",
  205. crewlinkpass: params.crewlinkpass ??
  206. Hive.box("profile").get("crewlink_pass") ??
  207. ""),
  208. );
  209. }),
  210. GoRoute(
  211. name: "crewlink.crewlist",
  212. path: 'crewlist',
  213. builder: (context, state) {
  214. final params = (state.extra as CrewlistPageParams?) ??
  215. const CrewlistPageParams();
  216. print(
  217. "${params.datestart} ${params.dateend} ${params.al} ${params.fnum} ${params.dep} ${params.des}");
  218. return CrewlistPage(
  219. params: CrewlistPageParams(
  220. datestart: params.datestart ?? //"04Dec23",
  221. Jiffy.now()
  222. .toUtc()
  223. //.subtract(days: 1)
  224. .format(pattern: "ddMMMyy"),
  225. dateend: params.dateend ?? //"05Dec23",
  226. params.datestart ??
  227. Jiffy.now().toUtc().format(pattern: "ddMMMyy"),
  228. al: params.al ?? "",
  229. fnum: params.fnum ?? "",
  230. dep: params.dep ?? "",
  231. des: params.des ?? "",
  232. crewlinkuser: params.crewlinkuser ??
  233. Hive.box("profile").get("crewlink_user") ??
  234. "",
  235. crewlinkpass: params.crewlinkpass ??
  236. Hive.box("profile").get("crewlink_pass") ??
  237. ""),
  238. );
  239. }),
  240. GoRoute(
  241. path: 'settings',
  242. builder: (context, state) => const CrewlinkForm()),
  243. ])
  244. ],
  245. );