fltinfo_page.dart 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. // ignore_for_file: unused_import
  2. import 'dart:developer';
  3. import 'package:collection/collection.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_riverpod/flutter_riverpod.dart';
  6. import 'package:gap/gap.dart';
  7. import 'package:go_router/go_router.dart';
  8. import 'package:google_fonts/google_fonts.dart';
  9. import 'package:jiffy/jiffy.dart';
  10. import 'package:tp5/core/core.dart';
  11. import 'package:tp5/csv/csv_data.dart';
  12. import 'package:tp5/csv/data.dart';
  13. import 'package:tp5/flightslist/w_flt.dart';
  14. import 'package:tp5/fltinfo/delaycodes.dart';
  15. import 'package:tp5/fltinfo/widget/w_cadre.dart';
  16. import 'package:tp5/ftl/widget/w_shadowbox.dart';
  17. import 'package:tp5/lido/lido_api.dart';
  18. import 'package:tp5/lido/model/Lidoapi_list.dart';
  19. import 'package:tp5/lido/model/Lidoapi_ofp.dart';
  20. import 'package:tp5/lido/w_lidoflt.dart';
  21. import 'package:tp5/pdf/pdf_page.dart';
  22. import 'package:tp5/roster/api/crewlink_api.dart';
  23. import 'package:tp5/roster/models/duty.dart';
  24. import 'package:tp5/roster/widgets/w_citypair.dart';
  25. import 'package:tp5/roster/widgets/w_crew.dart';
  26. import 'package:tp5/roster/widgets/w_day.dart';
  27. import 'package:tp5/roster/widgets/w_fnum.dart';
  28. import 'package:tp5/roster/widgets/w_hour.dart';
  29. import 'package:tp5/widgets/my_row.dart';
  30. class FltinfoPage extends ConsumerStatefulWidget {
  31. const FltinfoPage({required this.params, super.key});
  32. final FltinfoParams params;
  33. @override
  34. ConsumerState<ConsumerStatefulWidget> createState() => _FltinfoPageState();
  35. }
  36. class _FltinfoPageState extends ConsumerState<FltinfoPage> {
  37. @override
  38. void initState() {
  39. Future.delayed(Duration.zero).then(
  40. (v) async {
  41. _loadCrewFromCrewlink();
  42. _loadOfpFromLido();
  43. },
  44. );
  45. super.initState();
  46. }
  47. bool showNotifCrew = true;
  48. bool showAllLegs = false;
  49. bool _loadingCrew = false;
  50. List crew = [];
  51. int _crewPos = 0;
  52. Map<String, List<Pnleg>> crewPnleg = {};
  53. int crewPosPnleg = 0;
  54. int _legPos = 0;
  55. bool _loadingOFP = false;
  56. Jiffy _now = Jiffy.now().toUtc();
  57. _loadCrewFromCrewlink() async {
  58. setState(() {
  59. _loadingCrew = true;
  60. });
  61. final res = await ref.read(crewlinkapiProvider).showCrew(
  62. crewlist: true,
  63. start: widget.params.jdep?.format(pattern: "ddMMMyy") ?? "",
  64. end: (widget.params.jdep?.add(days: 1))?.format(pattern: "ddMMMyy") ??
  65. "",
  66. al: widget.params.al ?? "",
  67. fnum: widget.params.fnum ?? "",
  68. dep: widget.params.dep ?? "",
  69. des: widget.params.des ?? "");
  70. crew = res?["data"]?["leglist"] ?? [];
  71. //filter only flight withi 5hours from requested departure time
  72. // crew = crew.where((leg)=>);
  73. crew = crew
  74. .where((leg) =>
  75. jiffyfromddmmmyyhhmm("${leg[2]} ${leg[4]}")
  76. .diff(widget.params.jdep!, unit: Unit.hour)
  77. .abs() <
  78. 5)
  79. .toList();
  80. if (crew.isNotEmpty) _dateCrewbox = Jiffy.now().toUtc();
  81. //print(_crewList);
  82. setState(() {
  83. _loadingCrew = false;
  84. showNotifCrew = crew.isEmpty;
  85. });
  86. }
  87. bool _loadingLido = false;
  88. List<LidoapiList> lido = [];
  89. int _lidoPos = 0;
  90. //Map<String, List<LidoapiList>> lidoOfps = {};
  91. _loadOfpFromLido() async {
  92. setState(() {
  93. _loadingLido = true;
  94. });
  95. final res = await ref.read(lidoapiProvider).list(
  96. start: widget.params.jdep?.subtract(hours: 7),
  97. end: widget.params.jdes?.add(hours: 7),
  98. al: widget.params.al ?? "",
  99. fnum: widget.params.fnum ?? "",
  100. dep: widget.params.dep ?? "",
  101. des: widget.params.des ?? "");
  102. if ((res["error"] == null && res["data"] is List) ||
  103. (res["cache"] != null && (res["cache"]?["data"]) is List)) {
  104. _dateLido = Jiffy.now().toUtc();
  105. lido.clear();
  106. for (var e in (res["cache"]?["data"]) ?? res["data"] ?? []) {
  107. //print(e);
  108. lido.add(LidoapiList.fromJson(e));
  109. }
  110. }
  111. //print(lido);
  112. setState(() {
  113. _loadingLido = false;
  114. });
  115. }
  116. _titleInfo(String? title, String? info,
  117. {double sizetitle = 10,
  118. double sizeinfo = 16,
  119. Color color = Colors.blueGrey,
  120. bool bold = false}) =>
  121. Column(
  122. children: [
  123. Text(
  124. title ?? "---",
  125. style: TextStyle(color: Colors.grey, fontSize: sizetitle),
  126. ),
  127. Text(info ?? "---",
  128. style: TextStyle(
  129. color: color,
  130. fontSize: sizeinfo,
  131. fontWeight: bold ? FontWeight.bold : null)),
  132. ],
  133. );
  134. @override
  135. Widget build(BuildContext context) {
  136. final data = ref.watch(dataProvider);
  137. _dateAclegs = data.aclegupdate;
  138. _dateNotifiedcrew = data.pnlegupdate;
  139. _now = ref.watch(clockProvider);
  140. final pnlegs = ref
  141. .watch(pnlegProvider(FlightFilter(
  142. dep: widget.params.dep,
  143. arr: widget.params.des,
  144. al: widget.params.al,
  145. fnum: widget.params.fnum,
  146. jdep: widget.params.jdep,
  147. jarr: widget.params.jdes,
  148. )))
  149. .groupListsBy((Pnleg x) =>
  150. "${x.al} ${x.fnum} ${x.jdep?.format(pattern: "ddMMMyy")} ${x.dep} ${x.deptime} ${x.arrtime} ${x.arr}");
  151. //final qualif = ref.watch(dataProvider).qualif;
  152. crewPnleg = pnlegs;
  153. return Scaffold(
  154. appBar: AppBar(
  155. title: MyRow(
  156. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  157. children: [
  158. Text(
  159. '${widget.params.al}${widget.params.fnum} ${widget.params.dep}-${widget.params.des}'),
  160. const Gap(10),
  161. Text(widget.params.jdep!.format(pattern: "EEE ddMMM'yy"),
  162. style: const TextStyle(fontSize: 12)),
  163. ],
  164. ),
  165. leading: IconButton(
  166. icon: const Icon(Icons.arrow_back),
  167. onPressed: () {
  168. context.pop(context);
  169. },
  170. ),
  171. actions: const [
  172. Text(
  173. 'Flight info',
  174. style: TextStyle(
  175. fontSize: 12,
  176. fontWeight: FontWeight.w700,
  177. color: Colors.yellow),
  178. ),
  179. Gap(10)
  180. ],
  181. ),
  182. body: ListView(
  183. padding: const EdgeInsets.all(5),
  184. children: [
  185. WCadre(
  186. child: Column(
  187. children: [
  188. WDay(date: widget.params.jdep!),
  189. WFnum(al: "${widget.params.al}", fnum: "${widget.params.fnum}"),
  190. Row(
  191. mainAxisAlignment: MainAxisAlignment.center,
  192. mainAxisSize: MainAxisSize.max,
  193. children: [
  194. WCitypair(
  195. iata1: "${widget.params.dep}",
  196. iata2: widget.params.des ?? "---"),
  197. ],
  198. ),
  199. Row(
  200. mainAxisAlignment: MainAxisAlignment.center,
  201. mainAxisSize: MainAxisSize.max,
  202. children: [
  203. WHour(jiffy: widget.params.jdep!),
  204. if (widget.params.jdes != null) ...[
  205. const Gap(20),
  206. WHour(jiffy: widget.params.jdes!)
  207. ],
  208. ]),
  209. const Gap(10)
  210. ],
  211. ),
  212. ),
  213. const Gap(20),
  214. _crewBox(),
  215. const Gap(20),
  216. _notifiedCrew(),
  217. const Gap(20),
  218. _acStatus(),
  219. const Gap(20),
  220. _acLegs(),
  221. const Gap(20),
  222. _lidoBox(),
  223. const Gap(20),
  224. TextButton(
  225. onPressed: () async {
  226. await ref.read(dataProvider.notifier).loadPnlegsmois();
  227. },
  228. child: const Text("upd"))
  229. ],
  230. ),
  231. );
  232. }
  233. Jiffy? _dateCrewbox;
  234. _crewBox() {
  235. final crewlinkCredsaved = ref.watch(crewlinkapiProvider).credSaved();
  236. return WCadre(
  237. title: "Crew",
  238. titleright: _loadingCrew
  239. ? const SizedBox.square(
  240. dimension: 20,
  241. child: CircularProgressIndicator(),
  242. )
  243. : ElevatedButton.icon(
  244. label: const Text("Update", style: TextStyle(fontSize: 9)),
  245. onPressed: () async {
  246. await _loadCrewFromCrewlink();
  247. },
  248. icon: const Icon(Icons.update)),
  249. bottomright: _dateCrewbox != null
  250. ? Text("data retrieved ${_dateCrewbox?.from(_now)}",
  251. style: GoogleFonts.robotoMono(
  252. fontSize: 10, fontWeight: FontWeight.w300))
  253. : null,
  254. child: crew.isEmpty
  255. ? (!crewlinkCredsaved
  256. ? ElevatedButton.icon(
  257. label: const Text("Activate Crewlink",
  258. style: TextStyle(fontSize: 9)),
  259. onPressed: () {
  260. context.push("/crewlink/settings");
  261. },
  262. icon: const Icon(Icons.update))
  263. : const Text("No Flights found on Crewlink!"))
  264. : Column(
  265. children: [
  266. Column(children: [
  267. if (crew.length > 1)
  268. Row(mainAxisSize: MainAxisSize.min, children: [
  269. IconButton(
  270. iconSize: 30,
  271. onPressed: () {
  272. _crewPos =
  273. (_crewPos - 1 < 0 ? _crewPos : _crewPos - 1);
  274. setState(() {});
  275. },
  276. icon: const Icon(Icons.arrow_left)),
  277. Text("Flt ${_crewPos + 1} / ${crew.length}"),
  278. IconButton(
  279. iconSize: 30,
  280. onPressed: () {
  281. _crewPos = (_crewPos + 1 >= crew.length
  282. ? _crewPos
  283. : _crewPos + 1);
  284. setState(() {});
  285. },
  286. icon: const Icon(Icons.arrow_right))
  287. ]),
  288. Row(
  289. mainAxisSize: MainAxisSize.min,
  290. children: [
  291. Text(
  292. "${crew[_crewPos][1]} ${crew[_crewPos][2]} ${crew[_crewPos][3]} ${crew[_crewPos][4]} ${crew[_crewPos][5]} ${crew[_crewPos][6]}"),
  293. ],
  294. )
  295. ]),
  296. Padding(
  297. padding: const EdgeInsets.all(8.0),
  298. child: Column(
  299. children: crew[_crewPos][8]
  300. .map<Widget>((x) => WCrew(
  301. college: x[1],
  302. mle: x[0],
  303. base: x[3],
  304. name: x[5],
  305. ))
  306. .toList()),
  307. )
  308. ],
  309. ),
  310. );
  311. }
  312. Jiffy? _dateNotifiedcrew;
  313. _notifiedCrew() {
  314. final qualif = ref.watch(qualifProvider(CrewFilter()));
  315. // final data = ref.watch(dataProvider);
  316. return WCadre(
  317. title: "Notified Crew (alt)",
  318. titleright: IconButton(
  319. onPressed: () => setState(() {
  320. showNotifCrew = !showNotifCrew;
  321. }),
  322. icon: showNotifCrew
  323. ? const Icon(Icons.visibility)
  324. : const Icon(Icons.visibility_off)),
  325. bottomright: _dateNotifiedcrew != null
  326. ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
  327. style: GoogleFonts.robotoMono(
  328. fontSize: 10, fontWeight: FontWeight.w300))
  329. : null,
  330. child: crewPnleg.isEmpty
  331. ? const Text("No Flights found !")
  332. : !showNotifCrew
  333. ? TextButton(
  334. onPressed: () {
  335. showNotifCrew = true;
  336. setState(() {});
  337. },
  338. child: const Text("Tap to show"))
  339. : Column(
  340. children: [
  341. Column(children: [
  342. if (crewPnleg.length > 1)
  343. Row(mainAxisSize: MainAxisSize.min, children: [
  344. IconButton(
  345. iconSize: 30,
  346. onPressed: () {
  347. crewPosPnleg = (crewPosPnleg - 1 < 0
  348. ? crewPosPnleg
  349. : crewPosPnleg - 1);
  350. setState(() {});
  351. },
  352. icon: const Icon(Icons.arrow_left)),
  353. Text(
  354. "Flt ${crewPosPnleg + 1} / ${crewPnleg.keys.length}"),
  355. IconButton(
  356. iconSize: 30,
  357. onPressed: () {
  358. crewPosPnleg =
  359. (crewPosPnleg + 1 >= crewPnleg.keys.length
  360. ? crewPosPnleg
  361. : crewPosPnleg + 1);
  362. setState(() {});
  363. },
  364. icon: const Icon(Icons.arrow_right))
  365. ]),
  366. Row(
  367. mainAxisSize: MainAxisSize.min,
  368. children: [
  369. Text(crewPnleg.keys.elementAt(crewPosPnleg)),
  370. ],
  371. )
  372. ]),
  373. Padding(
  374. padding: const EdgeInsets.all(8.0),
  375. child: Column(
  376. children: crewPnleg[
  377. crewPnleg.keys.elementAt(crewPosPnleg)]!
  378. .mapIndexed((int i, leg) => {
  379. "index": i,
  380. "college": (["F", ""].contains(leg.type))
  381. ? "DH"
  382. : (qualif
  383. .firstWhereOrNull((e) =>
  384. (e.tlc == leg.tlc) &&
  385. (e.ac == leg.actype))
  386. ?.college ??
  387. qualif
  388. .firstWhereOrNull(
  389. (e) => e.tlc == leg.tlc)
  390. ?.college ??
  391. "--")
  392. })
  393. .sortedByCompare(
  394. (e) => e["college"].toString(), collegeSort)
  395. .map<Widget>((e) {
  396. final x =
  397. crewPnleg[crewPnleg.keys.elementAt(crewPosPnleg)]!
  398. .elementAt(e["index"] as int);
  399. final pn =
  400. qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  401. return WCrew(
  402. college: pn?.college,
  403. mle: x.tlc,
  404. base: pn?.base,
  405. name: "${pn?.lname}, ${pn?.fname}",
  406. );
  407. }).toList()),
  408. )
  409. // Padding(
  410. // padding: const EdgeInsets.all(8.0),
  411. // child: Column(
  412. // children: crewPnleg[
  413. // crewPnleg.keys.elementAt(crewPosPnleg)]!
  414. // .map<Widget>((x) {
  415. // final pn =
  416. // qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  417. // return WCrew(
  418. // college: pn?.college,
  419. // mle: x.tlc,
  420. // base: pn?.base,
  421. // name: "${pn?.lname}, ${pn?.fname}",
  422. // );
  423. // }).toList()),
  424. // )
  425. ],
  426. ),
  427. );
  428. }
  429. Jiffy? _dateAclegs;
  430. _acStatus() {
  431. final acleg = ref.watch(aclegProvider(FlightFilter(
  432. dep: widget.params.dep,
  433. arr: widget.params.des,
  434. al: widget.params.al,
  435. fnum: widget.params.fnum,
  436. jdep: widget.params.jdep,
  437. jarr: widget.params.jdes,
  438. )));
  439. return WCadre(
  440. title: "Aircraft & status",
  441. bottomright: _dateAclegs != null
  442. ? Text("data retrieved ${_dateAclegs?.from(_now)}",
  443. style: GoogleFonts.robotoMono(
  444. fontSize: 10, fontWeight: FontWeight.w300))
  445. : null,
  446. child: acleg.isEmpty
  447. ? const Text("No data found !")
  448. : Column(
  449. children: [
  450. Column(children: [
  451. if (acleg.length > 1)
  452. Row(mainAxisSize: MainAxisSize.min, children: [
  453. IconButton(
  454. iconSize: 30,
  455. onPressed: () {
  456. _legPos = (_legPos - 1 < 0 ? _legPos : _legPos - 1);
  457. setState(() {});
  458. },
  459. icon: const Icon(Icons.arrow_left)),
  460. Text("Flt ${_legPos + 1} / ${acleg.length}"),
  461. IconButton(
  462. iconSize: 30,
  463. onPressed: () {
  464. _legPos = (_legPos + 1 >= acleg.length
  465. ? _legPos
  466. : _legPos + 1);
  467. setState(() {});
  468. },
  469. icon: const Icon(Icons.arrow_right))
  470. ]),
  471. Row(
  472. mainAxisSize: MainAxisSize.min,
  473. children: [
  474. Text(
  475. "${acleg[_legPos].FN_CARRIER} ${acleg[_legPos].FN_NUMBER} ${acleg[_legPos].jdep?.format(pattern: "ddMMMyy")} ${acleg[_legPos].DEP_AP_ACTUAL} ${acleg[_legPos].jdep?.format(pattern: "HHmm")} ${acleg[_legPos].jarr?.format(pattern: "HHmm")} ${acleg[_legPos].ARR_AP_ACTUAL}"),
  476. ],
  477. )
  478. ]),
  479. Padding(
  480. padding: const EdgeInsets.all(8.0),
  481. child: Column(children: [
  482. SingleChildScrollView(
  483. scrollDirection: Axis.horizontal,
  484. child: Row(
  485. children: [
  486. _titleInfo("Reg", acleg[_legPos].AC_REGISTRATION,
  487. color: Colors.amber, bold: true),
  488. const Gap(20),
  489. _titleInfo("AC Type", acleg[_legPos].AC_SUBTYPE,
  490. sizeinfo: 14),
  491. const Gap(20),
  492. _titleInfo("Owner", acleg[_legPos].AC_OWNER),
  493. const Gap(50),
  494. _titleInfo("Version", acleg[_legPos].AC_VERSION,
  495. sizeinfo: 11),
  496. const Gap(20),
  497. _titleInfo("Booking", acleg[_legPos].pax_booked,
  498. color: Colors.white, bold: false),
  499. if (acleg[_legPos].pad_booked != null) ...[
  500. const Gap(20),
  501. _titleInfo("PAD", acleg[_legPos].pad_booked)
  502. ],
  503. ],
  504. ),
  505. ),
  506. const Gap(10),
  507. MyRow(
  508. children: [
  509. _titleInfo("Schedule",
  510. "${acleg[_legPos].jdepsched?.format(pattern: "ddMMM HH:mm")}-${acleg[_legPos].jarrsched?.format(pattern: "HH:mm")}",
  511. color: Colors.green[600]!,
  512. sizeinfo: 14,
  513. bold: true),
  514. const Gap(50),
  515. _titleInfo("actual/estimate dep/arr",
  516. "${acleg[_legPos].jdep?.format(pattern: "ddMMM HH:mm")}-${acleg[_legPos].jarr?.format(pattern: "HH:mm")}",
  517. color: Colors.cyan[600]!, sizeinfo: 14, bold: true),
  518. ],
  519. ),
  520. const Gap(10),
  521. MyRow(
  522. children: [
  523. _titleInfo("status", acleg[_legPos].flt_status,
  524. bold: true, sizeinfo: 14, color: Colors.yellow),
  525. if (acleg[_legPos].slot != null) ...[
  526. const Gap(50),
  527. _titleInfo("CTOT",
  528. "${(acleg[_legPos].slot?.year == 1970) ? "Cancel" : acleg[_legPos].slot?.format(pattern: "HH:mm")}",
  529. color: Colors.amber),
  530. ],
  531. if (acleg[_legPos].eet != null) ...[
  532. const Gap(50),
  533. _titleInfo("EET", "${acleg[_legPos].eet?.tohhmm}",
  534. sizetitle: 14, color: Colors.amber[900]!),
  535. ],
  536. ],
  537. ),
  538. if (acleg[_legPos].blocks.nonNulls.isNotEmpty)
  539. MyRow(children: [
  540. _titleInfo(
  541. "blocks",
  542. acleg[_legPos]
  543. .blocks
  544. .map((x) => x?.Hm ?? "----")
  545. .fold("", (t, e) => t == "" ? e : "$t , $e"),
  546. color: Colors.indigo,
  547. sizeinfo: 14,
  548. bold: true),
  549. ]),
  550. const Gap(10),
  551. if (((acleg[_legPos]).dla).any((e) => e[0] != null))
  552. Row(
  553. children: [
  554. Column(
  555. crossAxisAlignment: CrossAxisAlignment.start,
  556. children: [
  557. const Row(
  558. children: [
  559. Text("Delay Codes:"),
  560. ],
  561. ),
  562. ...((acleg[_legPos]).dla).map((d) => Column(
  563. children: [
  564. Row(
  565. crossAxisAlignment:
  566. CrossAxisAlignment.start,
  567. children: [
  568. Text(
  569. "DLA${d[0]}",
  570. style: const TextStyle(
  571. fontWeight: FontWeight.w600),
  572. ),
  573. const Gap(10),
  574. Text(
  575. (d[1] as Duration?)?.tohhmm ??
  576. "--:--",
  577. style: GoogleFonts.robotoMono(
  578. color: Colors.grey,
  579. fontSize: 12,
  580. fontWeight:
  581. FontWeight.w300)),
  582. const Gap(10),
  583. SizedBox(
  584. width: 200,
  585. child: Text(
  586. (Delaycodes.exp(d[0]) ?? "???")
  587. .toLowerCase()
  588. .capitalize(),
  589. style: const TextStyle(
  590. fontSize: 11),
  591. ),
  592. )
  593. ]),
  594. const Gap(20)
  595. ],
  596. ))
  597. ],
  598. ),
  599. ],
  600. ),
  601. ]),
  602. )
  603. ],
  604. ),
  605. );
  606. }
  607. _acLegs() {
  608. final acleg = ref.watch(aclegProvider(FlightFilter(
  609. dep: widget.params.dep,
  610. arr: widget.params.des,
  611. al: widget.params.al,
  612. fnum: widget.params.fnum,
  613. jdep: widget.params.jdep,
  614. jarr: widget.params.jdes,
  615. )));
  616. final aclegs = acleg.isEmpty
  617. ? <Acleg>[]
  618. : ref.watch(aclegProvider(FlightFilter(
  619. reg: acleg.isEmpty ? null : acleg.first.AC_REGISTRATION)));
  620. return WCadre(
  621. height: aclegs.isEmpty ? null : 350,
  622. title: "Aircraft legs",
  623. bottomright: _dateAclegs != null
  624. ? Text("data retrieved ${_dateAclegs?.from(_now)}",
  625. style: GoogleFonts.robotoMono(
  626. fontSize: 10, fontWeight: FontWeight.w300))
  627. : null,
  628. child: aclegs.isEmpty
  629. ? const Text("No leg found !")
  630. :
  631. // SingleChildScrollView(
  632. // scrollDirection: Axis.horizontal,
  633. // child:
  634. Column(
  635. children: [
  636. if (!showAllLegs)
  637. TextButton(
  638. onPressed: () => setState(() {
  639. showAllLegs = true;
  640. }),
  641. child: const Text("Show all legs")),
  642. ...aclegs
  643. .whereIndexed((i, leg) =>
  644. showAllLegs ||
  645. (i >= aclegs.indexOf(acleg.firstOrNull ?? Acleg()) - 3))
  646. .map((Acleg x) => InkWell(
  647. onTap: () => context.pushReplacement("/fltinfo",
  648. extra: FltinfoParams(
  649. al: x.FN_CARRIER,
  650. fnum: x.FN_NUMBER,
  651. jdep: x.jdep,
  652. jdes: x.jarr,
  653. dep: x.DEP_AP_ACTUAL,
  654. des: x.ARR_AP_SCHED,
  655. )),
  656. child: WFlt(
  657. acleg: x,
  658. hide: const ["actype"],
  659. highlight: acleg.firstOrNull == x,
  660. ),
  661. ))
  662. ],
  663. // ),
  664. ),
  665. );
  666. }
  667. Jiffy? _dateLido;
  668. _lidoBox() {
  669. final lidoactivated = ref.watch(lidoapiProvider).credSaved();
  670. return WCadre(
  671. title: "Lido OFP",
  672. titleright: _loadingLido
  673. ? const SizedBox.square(
  674. dimension: 20,
  675. child: CircularProgressIndicator(),
  676. )
  677. : ElevatedButton.icon(
  678. label: const Text("Update", style: TextStyle(fontSize: 9)),
  679. onPressed: () async {
  680. await _loadOfpFromLido();
  681. },
  682. icon: const Icon(Icons.update)),
  683. bottomright: _dateLido != null
  684. ? Text("data retrieved ${_dateLido?.from(_now)}",
  685. style: GoogleFonts.robotoMono(
  686. fontSize: 10, fontWeight: FontWeight.w300))
  687. : null,
  688. child: lido.isEmpty
  689. ? (lidoactivated
  690. ? const Text("No OFPs found on lido!")
  691. : ElevatedButton.icon(
  692. label: const Text("Activate Lido",
  693. style: TextStyle(fontSize: 9)),
  694. onPressed: () {
  695. context.push("/lido/settings");
  696. },
  697. icon: const Icon(Icons.update)))
  698. : Column(
  699. children: [
  700. Column(children: [
  701. if (lido.length > 1)
  702. Row(mainAxisSize: MainAxisSize.min, children: [
  703. IconButton(
  704. iconSize: 30,
  705. onPressed: () {
  706. _lidoPos =
  707. (_lidoPos - 1 < 0 ? _lidoPos : _lidoPos - 1);
  708. setState(() {});
  709. },
  710. icon: const Icon(Icons.arrow_left)),
  711. Text("Flt ${_lidoPos + 1} / ${lido.length}"),
  712. IconButton(
  713. iconSize: 30,
  714. onPressed: () {
  715. _lidoPos = (_lidoPos + 1 >= lido.length
  716. ? _lidoPos
  717. : _lidoPos + 1);
  718. setState(() {});
  719. },
  720. icon: const Icon(Icons.arrow_right))
  721. ]),
  722. Row(
  723. mainAxisSize: MainAxisSize.min,
  724. children: [
  725. Text(
  726. "${lido[_lidoPos].leg?.aircraftOperatorIata} ${lido[_lidoPos].leg?.flightNumber} ${Jiffy.parseFromMillisecondsSinceEpoch(lido[_lidoPos].leg?.estimatedDepartureTime ?? 0).format(pattern: "ddMMMyy")} ${lido[_lidoPos].leg?.departureAirport} ${Jiffy.parseFromMillisecondsSinceEpoch(lido[_lidoPos].leg?.estimatedDepartureTime ?? 0).Hm} ${Jiffy.parseFromMillisecondsSinceEpoch(lido[_lidoPos].leg?.estimatedTimeOfArrival ?? 0).Hm} ${lido[_lidoPos].leg?.destinationAirport}"),
  727. ],
  728. )
  729. ]),
  730. Padding(
  731. padding: const EdgeInsets.all(8.0),
  732. child: Column(children: [
  733. WLidoflt(lidoapilist: lido[_lidoPos]),
  734. _loadingOFP
  735. ? const CircularProgressIndicator()
  736. : ElevatedButton.icon(
  737. onPressed: () async {
  738. // final fileid = PathTo().lidoFile(
  739. // "${lido[_lidoPos].briefingId ?? ""}.pdf");
  740. final legid = lido[_lidoPos].briefingId ?? "";
  741. if (_loadingOFP == false) {
  742. setState(() {
  743. _loadingOFP = true;
  744. });
  745. final ofp = await ref
  746. .read(lidoapiProvider)
  747. .ofppdf(legid: legid);
  748. setState(() {
  749. _loadingOFP = false;
  750. });
  751. log(ofp.toString());
  752. if (((ofp["data"] is Map) &&
  753. (ofp["data"]?["downloaded"] ?? false) ==
  754. true) ||
  755. (ofp["cache"] != null)) {
  756. context.push("/pdf",
  757. extra: PdfPageParams(
  758. file: ofp["cache"] ??
  759. ofp["data"]?["fileid"] ??
  760. "",
  761. title: legid,
  762. initialZoom: 1));
  763. } else {
  764. context.showError(
  765. "Cannot download PDF File !!!");
  766. }
  767. }
  768. },
  769. icon: Image.asset(
  770. 'assets/pdficon.png',
  771. width: 28,
  772. ), //icon data for elevated button
  773. label: const Text(
  774. "Load OFP in\n PDF Format"), //label text
  775. // style: bottomnavstyle,
  776. ),
  777. ]),
  778. )
  779. ],
  780. ),
  781. );
  782. }
  783. }
  784. class FltinfoParams {
  785. const FltinfoParams({
  786. this.al,
  787. this.fnum,
  788. this.date,
  789. this.start,
  790. this.end,
  791. this.jdep,
  792. this.jdes,
  793. this.dep,
  794. this.des,
  795. });
  796. final Jiffy? start;
  797. final Jiffy? end;
  798. final String? al;
  799. final String? fnum;
  800. final String? date;
  801. final Jiffy? jdep;
  802. final Jiffy? jdes;
  803. final String? dep;
  804. final String? des;
  805. }
  806. int collegeSort(String a, String b) {
  807. // Define the order based on your requirements
  808. final order = ['CP', 'FO', 'PU', 'SE', 'ST', 'JU'];
  809. // Get the index of each element in the order list
  810. final indexA = order.indexOf(a);
  811. final indexB = order.indexOf(b);
  812. // Compare based on the index
  813. return indexA.compareTo(indexB);
  814. }