fltinfo_page.dart 32 KB

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