1
0

fltinfo_page.dart 33 KB

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