| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- // ignore_for_file: unused_import
- import 'dart:developer';
- import 'package:collection/collection.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:gap/gap.dart';
- import 'package:go_router/go_router.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:jiffy/jiffy.dart';
- import 'package:linear_progress_bar/linear_progress_bar.dart';
- import 'package:tp5/core/core.dart';
- import 'package:tp5/csv/csv_data.dart';
- import 'package:tp5/csv/data.dart';
- import 'package:tp5/flightslist/w_flt.dart';
- import 'package:tp5/fltinfo/delaycodes.dart';
- import 'package:tp5/fltinfo/widget/w_cadre.dart';
- import 'package:tp5/ftl/widget/w_shadowbox.dart';
- import 'package:tp5/lido/lido_api.dart';
- import 'package:tp5/lido/model/Lidoapi_list.dart';
- import 'package:tp5/lido/model/Lidoapi_ofp.dart';
- import 'package:tp5/lido/w_lidoflt.dart';
- import 'package:tp5/pdf/pdf_page.dart';
- import 'package:tp5/roster/api/crewlink_api.dart';
- import 'package:tp5/roster/models/duty.dart';
- import 'package:tp5/roster/widgets/w_airport.dart';
- import 'package:tp5/roster/widgets/w_citypair.dart';
- import 'package:tp5/roster/widgets/w_crew.dart';
- import 'package:tp5/roster/widgets/w_day.dart';
- import 'package:tp5/roster/widgets/w_fnum.dart';
- import 'package:tp5/roster/widgets/w_hour.dart';
- import 'package:tp5/widgets/my_row.dart';
- class DutyinfoPage extends ConsumerStatefulWidget {
- const DutyinfoPage({required this.params, super.key});
- final DutyinfoParams params;
- @override
- ConsumerState<ConsumerStatefulWidget> createState() => _DutyinfoPageState();
- }
- class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
- @override
- void initState() {
- Future.delayed(Duration.zero, () {
- crewPnlegLoad();
- });
- super.initState();
- }
- // List crew = [];
- Jiffy _now = Jiffy.now().toUtc();
- @override
- Widget build(BuildContext context) {
- //final data = ref.watch(dataProvider);
- //final pnleg = data.pnleg;
- // final _dateNotifiedcrew = data.pnlegupdate;
- _now = ref.watch(clockProvider);
- //final qualif = ref.watch(dataProvider).qualif;
- return Scaffold(
- appBar: AppBar(
- title: MyRow(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '${widget.params.dutytype ?? ""} ${widget.params.label ?? ""} ${widget.params.dep}${widget.params.des != null ? "-${widget.params.des}" : ""}'),
- const Gap(10),
- Text(widget.params.jdep!.format(pattern: "EEE ddMMM'yy"),
- style: const TextStyle(fontSize: 12)),
- ],
- ),
- leading: IconButton(
- icon: const Icon(Icons.arrow_back),
- onPressed: () {
- context.pop(context);
- },
- ),
- actions: [
- Text(
- '${widget.params.dutytype ?? "Duty"} info',
- style: TextStyle(
- fontSize: 12,
- fontWeight: FontWeight.w700,
- color: Colors.yellow),
- ),
- Gap(10)
- ],
- ),
- body: ListView(
- padding: const EdgeInsets.all(5),
- children: [
- WCadre(
- child: Column(
- children: [
- WDay(date: widget.params.jdep!),
- if (widget.params.label != null)
- Text(
- widget.params.label!,
- style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
- )
- else if (widget.params.dutytype != null)
- Text(
- widget.params.dutytype!,
- style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.max,
- children: [
- if (widget.params.des != null)
- WCitypair(
- iata1: "${widget.params.dep}",
- iata2: widget.params.des ?? "---")
- else
- WAirport(iata: widget.params.dep ?? "---"),
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.max,
- children: [
- WHour(jiffy: widget.params.jdep!),
- if (widget.params.jdes != null) ...[
- const Gap(20),
- WHour(jiffy: widget.params.jdes!)
- ],
- ]),
- const Gap(10)
- ],
- ),
- ),
- const Gap(20),
- _notifiedCrew(),
- ],
- ),
- );
- }
- Jiffy? _dateNotifiedcrew;
- static List<Pnleg> filterPnleg(Map data) {
- final List<Pnleg> pnleg = data["pnleg"];
- final DutyinfoParams filter = data["filter"];
- return pnleg
- .where((leg) => ((filter.jdep == null || leg.jdep == filter.jdep) &&
- (filter.jdes == null || leg.jarr == filter.jdes) &&
- (filter.dep == null || leg.dep == filter.dep) &&
- (filter.des == null || leg.arr == filter.des) &&
- (filter.label == null || leg.label == filter.label) &&
- (filter.dutytype == null || leg.dutytype == filter.dutytype)))
- .toList();
- }
- List<Pnleg> crewPnleg = [];
- bool crewPnlegLoading = false;
- crewPnlegLoad() async {
- crewPnlegLoading = true;
- setState(() {});
- final data = ref.watch(dataProvider);
- final pnleg = data.pnleg;
- _dateNotifiedcrew = data.pnlegupdate;
- crewPnleg =
- await compute(filterPnleg, {"pnleg": pnleg, "filter": widget.params});
- crewPnlegLoading = false;
- setState(() {});
- }
- _notifiedCrew() {
- final qualif = ref.watch(qualifProvider(CrewFilter()));
- // final crewPnleg = pnleg.where((leg) =>
- // ((widget.params.jdep == null || leg.jdep == widget.params.jdep) &&
- // (widget.params.jdes == null || leg.jarr == widget.params.jdes) &&
- // (widget.params.dep == null || leg.dep == widget.params.dep) &&
- // (widget.params.des == null || leg.arr == widget.params.des) &&
- // (widget.params.label == null || leg.label == widget.params.label) &&
- // (widget.params.dutytype == null ||
- // leg.dutytype == widget.params.dutytype)));
- return WCadre(
- titleright: crewPnlegLoading
- ? Padding(
- padding: const EdgeInsets.all(5.0),
- child: CircularProgressIndicator(),
- )
- : null,
- title: "Notified Crew (alt)",
- bottomright: _dateNotifiedcrew != null
- ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
- style: GoogleFonts.robotoMono(
- fontSize: 10, fontWeight: FontWeight.w300))
- : null,
- child: crewPnleg.isEmpty
- ? const Text("No data found !")
- : Column(
- children: [
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(
- children: crewPnleg
- .mapIndexed((int i, leg) => {
- "index": i,
- "college": (["F", ""].contains(leg.type))
- ? "DH"
- : (qualif
- .firstWhereOrNull((e) =>
- (e.tlc == leg.tlc) &&
- (e.ac == leg.actype))
- ?.college ??
- qualif
- .firstWhereOrNull(
- (e) => e.tlc == leg.tlc)
- ?.college ??
- "--")
- })
- .sortedByCompare(
- (e) => e["college"].toString(), collegeSort)
- .map<Widget>((e) {
- final x = crewPnleg.elementAt(e["index"] as int);
- final pn = qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
- return WCrew(
- college: pn?.college,
- mle: x.tlc,
- base: pn?.base,
- name: "${pn?.lname}, ${pn?.fname}",
- );
- }).toList()),
- )
- ],
- ),
- );
- }
- }
- class DutyinfoParams {
- const DutyinfoParams({
- this.date,
- this.start,
- this.end,
- this.label,
- this.dutytype,
- this.jdep,
- this.jdes,
- this.dep,
- this.des,
- });
- final Jiffy? start;
- final Jiffy? end;
- final String? date;
- final String? label;
- final String? dutytype;
- final Jiffy? jdep;
- final Jiffy? jdes;
- final String? dep;
- final String? des;
- }
- int collegeSort(String a, String b) {
- // Define the order based on your requirements
- final order = ['CP', 'FO', 'PU', 'SE', 'ST', 'JU'];
- // Get the index of each element in the order list
- final indexA = order.indexOf(a);
- final indexB = order.indexOf(b);
- // Compare based on the index
- return indexA.compareTo(indexB);
- }
|