fltinfo_page.dart 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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(res);
  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. final pn = (qualif.firstWhereOrNull((e) =>
  402. (e.tlc == x.tlc) && (e.ac == x.actype)) ??
  403. qualif.firstWhereOrNull((e) => e.tlc == x.tlc));
  404. return WCrew(
  405. college: (["F", ""].contains(x.type))
  406. ? "DH"
  407. : (pn?.college),
  408. mle: x.tlc,
  409. base: pn?.base,
  410. name: "${pn?.lname}, ${pn?.fname}",
  411. );
  412. }).toList()),
  413. )
  414. // Padding(
  415. // padding: const EdgeInsets.all(8.0),
  416. // child: Column(
  417. // children: crewPnleg[
  418. // crewPnleg.keys.elementAt(crewPosPnleg)]!
  419. // .map<Widget>((x) {
  420. // final pn =
  421. // qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  422. // return WCrew(
  423. // college: pn?.college,
  424. // mle: x.tlc,
  425. // base: pn?.base,
  426. // name: "${pn?.lname}, ${pn?.fname}",
  427. // );
  428. // }).toList()),
  429. // )
  430. ],
  431. ),
  432. );
  433. }
  434. Jiffy? _dateAclegs;
  435. _acStatus() {
  436. final acleg = ref.watch(aclegProvider(FlightFilter(
  437. dep: widget.params.dep,
  438. arr: widget.params.des,
  439. al: widget.params.al,
  440. fnum: widget.params.fnum,
  441. jdep: widget.params.jdep,
  442. jarr: widget.params.jdes,
  443. )));
  444. return WCadre(
  445. title: "Aircraft & status",
  446. bottomright: _dateAclegs != null
  447. ? Text("data retrieved ${_dateAclegs?.from(_now)}",
  448. style: GoogleFonts.robotoMono(
  449. fontSize: 10, fontWeight: FontWeight.w300))
  450. : null,
  451. child: acleg.isEmpty
  452. ? const Text("No data found !")
  453. : Column(
  454. children: [
  455. Column(children: [
  456. if (acleg.length > 1)
  457. Row(mainAxisSize: MainAxisSize.min, children: [
  458. IconButton(
  459. iconSize: 30,
  460. onPressed: () {
  461. _legPos = (_legPos - 1 < 0 ? _legPos : _legPos - 1);
  462. setState(() {});
  463. },
  464. icon: const Icon(Icons.arrow_left)),
  465. Text("Flt ${_legPos + 1} / ${acleg.length}"),
  466. IconButton(
  467. iconSize: 30,
  468. onPressed: () {
  469. _legPos = (_legPos + 1 >= acleg.length
  470. ? _legPos
  471. : _legPos + 1);
  472. setState(() {});
  473. },
  474. icon: const Icon(Icons.arrow_right))
  475. ]),
  476. Row(
  477. mainAxisSize: MainAxisSize.min,
  478. children: [
  479. Text(
  480. "${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}"),
  481. ],
  482. )
  483. ]),
  484. Padding(
  485. padding: const EdgeInsets.all(8.0),
  486. child: Column(children: [
  487. SingleChildScrollView(
  488. scrollDirection: Axis.horizontal,
  489. child: Row(
  490. children: [
  491. _titleInfo("Reg", acleg[_legPos].AC_REGISTRATION,
  492. color: Colors.amber, bold: true),
  493. const Gap(20),
  494. _titleInfo("AC Type", acleg[_legPos].AC_SUBTYPE,
  495. sizeinfo: 14),
  496. const Gap(20),
  497. _titleInfo("Owner", acleg[_legPos].AC_OWNER),
  498. const Gap(50),
  499. _titleInfo("Version", acleg[_legPos].AC_VERSION,
  500. sizeinfo: 11),
  501. const Gap(20),
  502. _titleInfo("Booking", acleg[_legPos].pax_booked,
  503. color: Colors.white, bold: false),
  504. if (acleg[_legPos].pad_booked != null) ...[
  505. const Gap(20),
  506. _titleInfo("PAD", acleg[_legPos].pad_booked)
  507. ],
  508. ],
  509. ),
  510. ),
  511. const Gap(10),
  512. MyRow(
  513. children: [
  514. _titleInfo("Schedule",
  515. "${acleg[_legPos].jdepsched?.format(pattern: "ddMMM HH:mm")}-${acleg[_legPos].jarrsched?.format(pattern: "HH:mm")}",
  516. color: Colors.green[600]!,
  517. sizeinfo: 14,
  518. bold: true),
  519. const Gap(50),
  520. _titleInfo("actual/estimate dep/arr",
  521. "${acleg[_legPos].jdep?.format(pattern: "ddMMM HH:mm")}-${acleg[_legPos].jarr?.format(pattern: "HH:mm")}",
  522. color: Colors.cyan[600]!, sizeinfo: 14, bold: true),
  523. ],
  524. ),
  525. const Gap(10),
  526. MyRow(
  527. children: [
  528. _titleInfo("status", acleg[_legPos].flt_status,
  529. bold: true, sizeinfo: 14, color: Colors.yellow),
  530. if (acleg[_legPos].slot != null) ...[
  531. const Gap(50),
  532. _titleInfo("CTOT",
  533. "${(acleg[_legPos].slot?.year == 1970) ? "Cancel" : acleg[_legPos].slot?.format(pattern: "HH:mm")}",
  534. color: Colors.amber),
  535. ],
  536. if (acleg[_legPos].eet != null) ...[
  537. const Gap(50),
  538. _titleInfo("EET", "${acleg[_legPos].eet?.tohhmm}",
  539. sizetitle: 14, color: Colors.amber[900]!),
  540. ],
  541. ],
  542. ),
  543. if (acleg[_legPos].blocks.nonNulls.isNotEmpty)
  544. MyRow(children: [
  545. _titleInfo(
  546. "blocks",
  547. acleg[_legPos]
  548. .blocks
  549. .map((x) => x?.Hm ?? "----")
  550. .fold("", (t, e) => t == "" ? e : "$t , $e"),
  551. color: Colors.indigo,
  552. sizeinfo: 14,
  553. bold: true),
  554. ]),
  555. const Gap(10),
  556. if (((acleg[_legPos]).dla).any((e) => e[0] != null))
  557. Row(
  558. children: [
  559. Column(
  560. crossAxisAlignment: CrossAxisAlignment.start,
  561. children: [
  562. const Row(
  563. children: [
  564. Text("Delay Codes:"),
  565. ],
  566. ),
  567. ...((acleg[_legPos]).dla).map((d) => Column(
  568. children: [
  569. Row(
  570. crossAxisAlignment:
  571. CrossAxisAlignment.start,
  572. children: [
  573. Text(
  574. "DLA${d[0]}",
  575. style: const TextStyle(
  576. fontWeight: FontWeight.w600),
  577. ),
  578. const Gap(10),
  579. Text(
  580. (d[1] as Duration?)?.tohhmm ??
  581. "--:--",
  582. style: GoogleFonts.robotoMono(
  583. color: Colors.grey,
  584. fontSize: 12,
  585. fontWeight:
  586. FontWeight.w300)),
  587. const Gap(10),
  588. SizedBox(
  589. width: 200,
  590. child: Text(
  591. (Delaycodes.exp(d[0]) ?? "???")
  592. .toLowerCase()
  593. .capitalize(),
  594. style: const TextStyle(
  595. fontSize: 11),
  596. ),
  597. )
  598. ]),
  599. const Gap(20)
  600. ],
  601. ))
  602. ],
  603. ),
  604. ],
  605. ),
  606. ]),
  607. )
  608. ],
  609. ),
  610. );
  611. }
  612. _acLegs() {
  613. final acleg = ref.watch(aclegProvider(FlightFilter(
  614. dep: widget.params.dep,
  615. arr: widget.params.des,
  616. al: widget.params.al,
  617. fnum: widget.params.fnum,
  618. jdep: widget.params.jdep,
  619. jarr: widget.params.jdes,
  620. )));
  621. final aclegs = acleg.isEmpty
  622. ? <Acleg>[]
  623. : ref.watch(aclegProvider(FlightFilter(
  624. reg: acleg.isEmpty ? null : acleg.first.AC_REGISTRATION)));
  625. return WCadre(
  626. height: aclegs.isEmpty ? null : 350,
  627. title: "Aircraft legs",
  628. bottomright: _dateAclegs != null
  629. ? Text("data retrieved ${_dateAclegs?.from(_now)}",
  630. style: GoogleFonts.robotoMono(
  631. fontSize: 10, fontWeight: FontWeight.w300))
  632. : null,
  633. child: aclegs.isEmpty
  634. ? const Text("No leg found !")
  635. :
  636. // SingleChildScrollView(
  637. // scrollDirection: Axis.horizontal,
  638. // child:
  639. Column(
  640. children: [
  641. if (!showAllLegs)
  642. TextButton(
  643. onPressed: () => setState(() {
  644. showAllLegs = true;
  645. }),
  646. child: const Text("Show all legs")),
  647. ...aclegs
  648. .whereIndexed((i, leg) =>
  649. showAllLegs ||
  650. (i >= aclegs.indexOf(acleg.firstOrNull ?? Acleg()) - 3))
  651. .map((Acleg x) => InkWell(
  652. onTap: () => context.pushReplacement("/fltinfo",
  653. extra: FltinfoParams(
  654. al: x.FN_CARRIER,
  655. fnum: x.FN_NUMBER,
  656. jdep: x.jdep,
  657. jdes: x.jarr,
  658. dep: x.DEP_AP_ACTUAL,
  659. des: x.ARR_AP_SCHED,
  660. )),
  661. child: WFlt(
  662. acleg: x,
  663. hide: const ["actype"],
  664. highlight: acleg.firstOrNull == x,
  665. ),
  666. ))
  667. ],
  668. // ),
  669. ),
  670. );
  671. }
  672. Jiffy? _dateLido;
  673. _lidoBox() {
  674. final lidoactivated = ref.watch(lidoapiProvider).credSaved();
  675. return WCadre(
  676. title: "Lido OFP",
  677. titleright: _loadingLido
  678. ? const SizedBox.square(
  679. dimension: 20,
  680. child: CircularProgressIndicator(),
  681. )
  682. : lidoactivated
  683. ? (ElevatedButton.icon(
  684. label: const Text("Update", style: TextStyle(fontSize: 9)),
  685. onPressed: () async {
  686. await _loadOfpFromLido();
  687. },
  688. icon: const Icon(Icons.update)))
  689. : Text("Lido is not activated!"),
  690. bottomright: _dateLido != null
  691. ? Text("data retrieved ${_dateLido?.from(_now)}",
  692. style: GoogleFonts.robotoMono(
  693. fontSize: 10, fontWeight: FontWeight.w300))
  694. : null,
  695. child: !lidoactivated
  696. ? ElevatedButton.icon(
  697. label: const Text("Activate Lido", style: TextStyle(fontSize: 9)),
  698. onPressed: () {
  699. context.push("/lido/settings");
  700. },
  701. icon: const Icon(Icons.update))
  702. : (lido.isEmpty
  703. ? const Text("No OFPs found on lido!")
  704. : Column(
  705. children: [
  706. Column(children: [
  707. if (lido.length > 1)
  708. Row(mainAxisSize: MainAxisSize.min, children: [
  709. IconButton(
  710. iconSize: 30,
  711. onPressed: () {
  712. _lidoPos = (_lidoPos - 1 < 0
  713. ? _lidoPos
  714. : _lidoPos - 1);
  715. setState(() {});
  716. },
  717. icon: const Icon(Icons.arrow_left)),
  718. Text("Flt ${_lidoPos + 1} / ${lido.length}"),
  719. IconButton(
  720. iconSize: 30,
  721. onPressed: () {
  722. _lidoPos = (_lidoPos + 1 >= lido.length
  723. ? _lidoPos
  724. : _lidoPos + 1);
  725. setState(() {});
  726. },
  727. icon: const Icon(Icons.arrow_right))
  728. ]),
  729. Row(
  730. mainAxisSize: MainAxisSize.min,
  731. children: [
  732. Text(
  733. "${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}"),
  734. ],
  735. )
  736. ]),
  737. Padding(
  738. padding: const EdgeInsets.all(8.0),
  739. child: Column(children: [
  740. WLidoflt(lidoapilist: lido[_lidoPos]),
  741. _loadingOFP
  742. ? const CircularProgressIndicator()
  743. : ElevatedButton.icon(
  744. onPressed: () async {
  745. // final fileid = PathTo().lidoFile(
  746. // "${lido[_lidoPos].briefingId ?? ""}.pdf");
  747. final legid = lido[_lidoPos].briefingId ?? "";
  748. if (_loadingOFP == false) {
  749. setState(() {
  750. _loadingOFP = true;
  751. });
  752. final ofp = await ref
  753. .read(lidoapiProvider)
  754. .ofppdf(legid: legid);
  755. setState(() {
  756. _loadingOFP = false;
  757. });
  758. log(ofp.toString());
  759. if (((ofp["data"] is Map) &&
  760. (ofp["data"]?["downloaded"] ??
  761. false) ==
  762. true) ||
  763. (ofp["cache"] != null)) {
  764. context.push("/pdf",
  765. extra: PdfPageParams(
  766. file: ofp["cache"] ??
  767. ofp["data"]?["fileid"] ??
  768. "",
  769. title: legid,
  770. initialZoom: 1));
  771. } else {
  772. context.showError(
  773. "Cannot download PDF File !!!");
  774. }
  775. }
  776. },
  777. icon: Image.asset(
  778. 'assets/pdficon.png',
  779. width: 28,
  780. ), //icon data for elevated button
  781. label: const Text(
  782. "Load OFP in\n PDF Format"), //label text
  783. // style: bottomnavstyle,
  784. ),
  785. ]),
  786. )
  787. ],
  788. )),
  789. );
  790. }
  791. }
  792. class FltinfoParams {
  793. const FltinfoParams({
  794. this.al,
  795. this.fnum,
  796. this.date,
  797. this.start,
  798. this.end,
  799. this.jdep,
  800. this.jdes,
  801. this.dep,
  802. this.des,
  803. });
  804. final Jiffy? start;
  805. final Jiffy? end;
  806. final String? al;
  807. final String? fnum;
  808. final String? date;
  809. final Jiffy? jdep;
  810. final Jiffy? jdes;
  811. final String? dep;
  812. final String? des;
  813. }
  814. int collegeSort(String a, String b) {
  815. // Define the order based on your requirements
  816. final order = ['CP', 'FO', 'PU', 'SE', 'ST', 'JU', 'DH'];
  817. // Get the index of each element in the order list
  818. final indexA = order.indexOf(a);
  819. final indexB = order.indexOf(b);
  820. // Compare based on the index
  821. return indexA.compareTo(indexB);
  822. }