routes.dart 9.3 KB

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