w_duty.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. import 'package:flutter/material.dart';
  2. import 'package:gap/gap.dart';
  3. import 'package:tp5/roster/models/duty.dart';
  4. import 'package:tp5/roster/widgets/w_airport.dart';
  5. import 'package:tp5/roster/widgets/w_citypair.dart';
  6. import 'package:tp5/roster/widgets/w_fnum.dart';
  7. import 'package:tp5/roster/widgets/w_hour.dart';
  8. class WDuty extends StatelessWidget {
  9. const WDuty({super.key, required this.duty, this.date, this.onTap});
  10. final Duty duty;
  11. final String? date;
  12. final dynamic onTap;
  13. Widget _checkDutyType() {
  14. final String widgetdate = date ?? duty.date;
  15. if (duty.type == "flight") {
  16. return Card(
  17. color: Colors.grey[800],
  18. shape: RoundedRectangleBorder(
  19. borderRadius: BorderRadius.circular(6.0),
  20. ),
  21. elevation: 8.0,
  22. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  23. child: SizedBox(
  24. child: ListTile(
  25. contentPadding:
  26. const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  27. leading: Icon(duty.icon),
  28. title: Row(
  29. children: [
  30. WCitypair(iata1: duty.data["dep"], iata2: duty.data["des"]),
  31. if (duty.data["req"] != null) ...[
  32. const Gap(10),
  33. Expanded(child: Container()),
  34. const Text("Requested",
  35. style: TextStyle(color: Colors.white38, fontSize: 12))
  36. ],
  37. ],
  38. ),
  39. subtitle: Row(
  40. children: [
  41. WFnum(al: duty.data["al"], fnum: duty.data["fnum"]),
  42. const Gap(20),
  43. if (duty.data["actype"] != null)
  44. Text("${duty.data["actype"] ?? ""}",
  45. style: const TextStyle(
  46. color: Colors.yellow, fontWeight: FontWeight.w700)),
  47. if (duty.data["remark"] != null) ...[
  48. const Gap(10),
  49. Expanded(child: Container()),
  50. _text(duty.data["remark"])
  51. ],
  52. ],
  53. ),
  54. trailing: Row(mainAxisSize: MainAxisSize.min, children: [
  55. WHour(jiffy: duty.start!, hide: duty.date != widgetdate),
  56. const Gap(10),
  57. WHour(
  58. jiffy: duty.end!,
  59. color: duty.end!.format(pattern: "yyyy-MM-dd") == widgetdate
  60. ? null
  61. : Colors.black)
  62. ]),
  63. ),
  64. ),
  65. );
  66. } else if (duty.type == "dhflight") {
  67. return Card(
  68. color: Colors.blueGrey[800],
  69. shape: RoundedRectangleBorder(
  70. borderRadius: BorderRadius.circular(6.0),
  71. ),
  72. elevation: 8.0,
  73. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  74. child: SizedBox(
  75. child: ListTile(
  76. contentPadding:
  77. const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  78. leading: Icon(duty.icon),
  79. title: Row(
  80. children: [
  81. Container(
  82. padding: const EdgeInsets.all(2),
  83. color: Colors.blueGrey[900],
  84. child: const Text("DH",
  85. style:
  86. TextStyle(fontWeight: FontWeight.w400, fontSize: 12)),
  87. ),
  88. const Gap(10),
  89. WCitypair(iata1: duty.data["dep"], iata2: duty.data["des"]),
  90. if (duty.data["req"] != null) ...[
  91. const Gap(10),
  92. Expanded(child: Container()),
  93. const Text("Requested",
  94. style: TextStyle(color: Colors.white38, fontSize: 12))
  95. ],
  96. ],
  97. ),
  98. subtitle: Row(
  99. children: [
  100. WFnum(al: duty.data["al"], fnum: duty.data["fnum"]),
  101. if (duty.data["remark"] != null) ...[
  102. const Gap(10),
  103. Expanded(child: Container()),
  104. _text(duty.data["remark"])
  105. ],
  106. ],
  107. ),
  108. trailing: Row(mainAxisSize: MainAxisSize.min, children: [
  109. WHour(jiffy: duty.start!, hide: duty.date != widgetdate),
  110. const Gap(10),
  111. WHour(
  112. jiffy: duty.end!,
  113. color: duty.end!.format(pattern: "yyyy-MM-dd") == widgetdate
  114. ? null
  115. : Colors.black)
  116. ]),
  117. ),
  118. ),
  119. );
  120. } else if (duty.type == "dhlimo") {
  121. return Card(
  122. color: Colors.blueGrey[800],
  123. shape: RoundedRectangleBorder(
  124. borderRadius: BorderRadius.circular(6.0),
  125. ),
  126. elevation: 8.0,
  127. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  128. child: SizedBox(
  129. child: ListTile(
  130. contentPadding:
  131. const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  132. leading: Icon(duty.icon),
  133. title: Row(
  134. children: [
  135. Container(
  136. padding: const EdgeInsets.all(2),
  137. color: Colors.blueGrey[900],
  138. child: const Text("DH",
  139. style:
  140. TextStyle(fontWeight: FontWeight.w400, fontSize: 12)),
  141. ),
  142. const Gap(10),
  143. WCitypair(iata1: duty.data["dep"], iata2: duty.data["des"]),
  144. if (duty.data["req"] != null) ...[
  145. const Gap(10),
  146. Expanded(child: Container()),
  147. const Text("Requested",
  148. style: TextStyle(color: Colors.white38, fontSize: 12))
  149. ],
  150. ],
  151. ),
  152. subtitle: Row(
  153. children: [
  154. const WFnum(al: "", fnum: "LIMO"),
  155. if (duty.data["remark"] != null) ...[
  156. const Gap(10),
  157. Expanded(child: Container()),
  158. _text(duty.data["remark"])
  159. ],
  160. ],
  161. ),
  162. trailing: Row(mainAxisSize: MainAxisSize.min, children: [
  163. WHour(jiffy: duty.start!, hide: duty.date != widgetdate),
  164. const Gap(10),
  165. WHour(
  166. jiffy: duty.end!,
  167. color: duty.end!.format(pattern: "yyyy-MM-dd") == widgetdate
  168. ? null
  169. : Colors.black)
  170. ]),
  171. ),
  172. ),
  173. );
  174. } else if (duty.type == "wholeday" ||
  175. (duty.data["hdep"] == "0100" && duty.data["hdes"] == "2300") ||
  176. (duty.data["hdep"] == "0001" && duty.data["hdes"] == "2300")) {
  177. return Card(
  178. color: Colors.white10,
  179. shape: RoundedRectangleBorder(
  180. borderRadius: BorderRadius.circular(6.0),
  181. ),
  182. elevation: 2.0,
  183. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  184. child: SizedBox(
  185. child: ListTile(
  186. contentPadding:
  187. const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  188. title: Row(
  189. mainAxisAlignment: MainAxisAlignment.center,
  190. mainAxisSize: MainAxisSize.max,
  191. children: [
  192. Text(
  193. duty.data["label"],
  194. style: TextStyle(
  195. fontSize: (duty.data["label"]).toString().length < 16
  196. ? 24
  197. : 12),
  198. ),
  199. const Gap(10),
  200. WAirport(
  201. iata: duty.data["dep"],
  202. size: 12,
  203. ),
  204. const Gap(5),
  205. if (duty.data["req"] != null) ...[
  206. const Gap(10),
  207. const Text("Requested",
  208. style: TextStyle(color: Colors.white38, fontSize: 12))
  209. ],
  210. ],
  211. ),
  212. subtitle: Row(
  213. children: [
  214. if (duty.data["remark"] != null) ...[
  215. const Gap(10),
  216. Expanded(child: Container()),
  217. _text(duty.data["remark"])
  218. ],
  219. ],
  220. ),
  221. ),
  222. ),
  223. );
  224. } else if (duty.type == "ground") {
  225. return Card(
  226. color: Colors.blueGrey[700],
  227. shape: RoundedRectangleBorder(
  228. borderRadius: BorderRadius.circular(6.0),
  229. ),
  230. elevation: 8.0,
  231. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  232. child: SizedBox(
  233. child: ListTile(
  234. contentPadding:
  235. const EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  236. leading: Icon(duty.icon),
  237. title: Row(
  238. children: [
  239. Text(
  240. duty.data["label"],
  241. style: TextStyle(
  242. fontSize: (duty.data["label"]).toString().length < 16
  243. ? 24
  244. : 12),
  245. ),
  246. const Gap(10),
  247. WAirport(
  248. iata: duty.data["dep"],
  249. size: 12,
  250. ),
  251. const Gap(5),
  252. if (duty.data["req"] != null) ...[
  253. const Gap(10),
  254. Expanded(child: Container()),
  255. const Text("Requested",
  256. style: TextStyle(color: Colors.white38, fontSize: 12))
  257. ],
  258. ],
  259. ),
  260. subtitle: Row(
  261. children: [
  262. if (duty.data["actype"] != null) ...[
  263. const Text("SIMU"),
  264. const Gap(10),
  265. Text("${duty.data["actype"] ?? ""}",
  266. style: const TextStyle(
  267. color: Colors.yellow, fontWeight: FontWeight.w700))
  268. ],
  269. if (duty.data["remark"] != null) ...[
  270. const Gap(10),
  271. Expanded(child: Container()),
  272. _text(duty.data["remark"])
  273. ],
  274. ],
  275. ),
  276. trailing: Row(mainAxisSize: MainAxisSize.min, children: [
  277. WHour(jiffy: duty.start!, hide: duty.date != widgetdate),
  278. const Gap(10),
  279. WHour(
  280. jiffy: duty.end!,
  281. color: duty.end!.format(pattern: "yyyy-MM-dd") == widgetdate
  282. ? null
  283. : Colors.black)
  284. ]),
  285. ),
  286. ),
  287. );
  288. } else if (duty.type == "checkin") {
  289. return Row(mainAxisAlignment: MainAxisAlignment.start, children: [
  290. Container(
  291. padding: const EdgeInsets.symmetric(horizontal: 5),
  292. color: Colors.white10,
  293. child: Text(
  294. ">>> C/I ${duty.data["station"]} ${duty.data["time"]}",
  295. style: const TextStyle(letterSpacing: 2, color: Colors.white54),
  296. ),
  297. )
  298. ]);
  299. } else if (duty.type == "checkout") {
  300. return Row(mainAxisAlignment: MainAxisAlignment.end, children: [
  301. Container(
  302. padding: const EdgeInsets.symmetric(horizontal: 5),
  303. color: Colors.white10,
  304. child: Text(
  305. "${duty.data["time"]} ${duty.data["station"]} C/O <<<",
  306. style: const TextStyle(letterSpacing: 2, color: Colors.white54),
  307. ),
  308. )
  309. ]);
  310. } else if (duty.type == "credit") {
  311. return Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
  312. // const Divider(),
  313. Text(
  314. "credit: [${duty.data["credit"]}]",
  315. style: TextStyle(
  316. fontSize: 12, letterSpacing: 2, color: Colors.blue[400]),
  317. )
  318. ]);
  319. } else if (duty.type == "changed") {
  320. return Card(
  321. color: Colors.orange.shade800,
  322. shape: RoundedRectangleBorder(
  323. borderRadius: BorderRadius.circular(5.0),
  324. ),
  325. elevation: 2.0,
  326. margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  327. child: const SizedBox(
  328. child: ListTile(
  329. contentPadding:
  330. EdgeInsets.symmetric(horizontal: 20.0, vertical: 0.0),
  331. title: Row(
  332. mainAxisAlignment: MainAxisAlignment.center,
  333. mainAxisSize: MainAxisSize.max,
  334. children: [
  335. Text(
  336. "CHANGED",
  337. style: TextStyle(fontSize: 24),
  338. ),
  339. ]),
  340. ),
  341. ),
  342. );
  343. } else if (duty.type == "unknown") {
  344. return Tooltip(
  345. message: "${duty.data["unknown"]}",
  346. child: Text(
  347. overflow: TextOverflow.fade,
  348. "${duty.data["unknown"]}",
  349. style: const TextStyle(fontSize: 10)));
  350. } else {
  351. return Tooltip(
  352. message: "${duty.data}",
  353. child: Text(
  354. overflow: TextOverflow.fade,
  355. "${duty.data}",
  356. style: const TextStyle(fontSize: 10)));
  357. }
  358. }
  359. @override
  360. Widget build(BuildContext context) {
  361. return InkWell(
  362. onTap: onTap,
  363. child: _checkDutyType(),
  364. );
  365. }
  366. Widget _text(String? msg) => Flexible(
  367. child: Tooltip(
  368. message: msg ?? "",
  369. child: Text(msg ?? "",
  370. overflow: TextOverflow.ellipsis,
  371. style: const TextStyle(color: Colors.white38, fontSize: 12))));
  372. }