1
0

flightslist_page.dart.bak2 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import 'package:collection/collection.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import 'package:go_router/go_router.dart';
  5. import 'package:tp5/core/basic_page.dart';
  6. import 'package:tp5/core/utils.dart';
  7. import 'package:tp5/csv/data.dart';
  8. import 'package:tp5/fltinfo/view/fltinfo_page.dart';
  9. import 'package:tp5/widgets/my_col.dart';
  10. class FlightslistPage extends ConsumerStatefulWidget {
  11. const FlightslistPage({super.key});
  12. @override
  13. ConsumerState<ConsumerStatefulWidget> createState() =>
  14. _FlightslistPageState();
  15. }
  16. class _FlightslistPageState extends ConsumerState<FlightslistPage> {
  17. bool showAllLegs = false;
  18. _acLegs() {
  19. final aclegs = ref.watch(dataProvider).acleg;
  20. final now = ref.watch(clockProvider);
  21. final firstlegafternow =
  22. aclegs.firstWhereOrNull((l) => l.jdep!.isSameOrAfter(now)) ?? Acleg();
  23. return Container(
  24. child: aclegs.isEmpty
  25. ? const Text("No leg found !")
  26. : SingleChildScrollView(
  27. scrollDirection: Axis.horizontal,
  28. child: MyCol(
  29. children: [
  30. if (!showAllLegs)
  31. TextButton(
  32. onPressed: () => setState(() {
  33. showAllLegs = true;
  34. }),
  35. child: const Text("Show all legs")),
  36. DataTable(
  37. showCheckboxColumn: false,
  38. border: TableBorder.all(width: 2),
  39. headingRowHeight: 5,
  40. columnSpacing: 20,
  41. dataRowMaxHeight: 31,
  42. dataRowMinHeight: 30,
  43. columns: [
  44. "Time",
  45. "Dep-Arr",
  46. "FNum",
  47. "Reg",
  48. "Status",
  49. "Delay"
  50. ].map((e) => DataColumn(label: Text(e))).toList(),
  51. rows: aclegs
  52. .whereIndexed((i, leg) =>
  53. showAllLegs ||
  54. (i >= aclegs.indexOf(firstlegafternow) - 10))
  55. .map(
  56. (Acleg x) => DataRow(
  57. onSelectChanged: (s) => context.push("/fltinfo",
  58. extra: FltinfoParams(
  59. al: x.FN_CARRIER,
  60. fnum: x.FN_NUMBER,
  61. jdep: x.jdep,
  62. jdes: x.jarr,
  63. dep: x.DEP_AP_ACTUAL,
  64. des: x.ARR_AP_SCHED)),
  65. color: WidgetStateProperty.all(
  66. (x == firstlegafternow)
  67. ? Colors.purple[900]
  68. : ((x.jdep!.isBefore(now))
  69. ? Colors.black
  70. : const Color.fromARGB(
  71. 255, 2, 21, 30))),
  72. cells: [
  73. DataCell(Column(
  74. children: [
  75. Text(
  76. "${x.jdep?.format(pattern: "dd MMM'yy")}",
  77. style: TextStyle(
  78. color: Colors.blueGrey[200],
  79. fontWeight: FontWeight.w700,
  80. fontSize: 10),
  81. ),
  82. Text(
  83. "${x.jdep?.Hm ?? ""} ${x.jarr?.Hm ?? ""}",
  84. style: const TextStyle(
  85. color: Colors.blueGrey,
  86. fontWeight: FontWeight.w600,
  87. fontSize: 12),
  88. ),
  89. ],
  90. )),
  91. DataCell(Text(
  92. " ${x.DEP_AP_ACTUAL ?? ""}-${x.ARR_AP_ACTUAL ?? ""}",
  93. )),
  94. DataCell(Text(
  95. " ${x.FN_CARRIER ?? ""}${x.FN_NUMBER ?? ""}${x.FN_SUFFIX ?? ""}",
  96. style: const TextStyle(fontSize: 12),
  97. )),
  98. DataCell(Text(x.flt_status,
  99. style: TextStyle(
  100. fontSize: 10,
  101. fontWeight: FontWeight.bold,
  102. color: x.flt_status == "Arrived"
  103. ? Colors.cyan
  104. : Colors.amber))),
  105. DataCell(Text(x.AC_REGISTRATION ?? "-----",
  106. style: TextStyle(
  107. fontSize: 10,
  108. fontWeight: FontWeight.bold,
  109. color: x.EMPLOYER_COCKPIT == "TU"
  110. ? Colors.green
  111. : Colors.red))),
  112. DataCell(
  113. placeholder: true,
  114. (x.jdep!.isAfter(x.jdepsched!))
  115. ? Text(x.jdep!.dateTime
  116. .difference(x.jdepsched!.dateTime)
  117. .tohhmm)
  118. : const Text("")),
  119. ]),
  120. )
  121. .toList()),
  122. ],
  123. ),
  124. ),
  125. );
  126. }
  127. final bottomnavstyle = ElevatedButton.styleFrom(
  128. shape: RoundedRectangleBorder(
  129. borderRadius: BorderRadius.circular(5.0),
  130. ),
  131. backgroundColor:
  132. const Color.fromARGB(255, 0, 36, 53) //elevated btton background color
  133. );
  134. @override
  135. Widget build(BuildContext context) {
  136. return BasicPage(
  137. appBar: AppBar(
  138. title: Text('Flights List'),
  139. ), bottomNavigationBar: Container(
  140. padding: const EdgeInsets.all(8),
  141. // color: Colors.black,
  142. decoration: BoxDecoration(
  143. gradient: LinearGradient(
  144. begin: Alignment.topCenter,
  145. end: Alignment.bottomCenter,
  146. colors: [
  147. Colors.grey[700]!,
  148. Colors.black,
  149. ],
  150. )),
  151. child: Row(
  152. mainAxisAlignment: MainAxisAlignment.spaceAround,
  153. children: [
  154. ElevatedButton.icon(
  155. onPressed: () {
  156. _showMonths(context);
  157. },
  158. icon: const Icon(
  159. Icons.calendar_month), //icon data for elevated button
  160. label: const Text("Change\nMonth"), //label text
  161. style: bottomnavstyle,
  162. ),
  163. body: Center(
  164. child: _acLegs(),
  165. ),
  166. );
  167. }
  168. }