1
0

fltinfo_page.dart 32 KB

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