1
0

duty.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:flutter/material.dart';
  2. import 'package:jiffy/jiffy.dart';
  3. class Duty {
  4. String date;
  5. String type;
  6. Map data;
  7. int order;
  8. Jiffy get jdate => Jiffy.parse(date, isUtc: true);
  9. Jiffy? get start => ((data["hdep"] ?? data["start"]) != null ||
  10. type == "checkin")
  11. ? Jiffy.parse(
  12. "$date ${_addChar(data["hdep"] ?? data["start"] ?? data["time"])}",
  13. isUtc: true,
  14. pattern: "yyyy-MM-dd HH:mm")
  15. : null;
  16. Jiffy? get end {
  17. final Jiffy? out = ((data["hdes"] ?? data["end"]) != null ||
  18. type == "checkout")
  19. ? Jiffy.parse(
  20. "$date ${_addChar(data["hdes"] ?? data["end"] ?? data["time"])}",
  21. isUtc: true,
  22. pattern: "yyyy-MM-dd HH:mm")
  23. : null;
  24. if (out != null && start != null && out.isBefore(start!)) {
  25. return out.add(days: 1);
  26. } else {
  27. return out;
  28. }
  29. }
  30. IconData get icon {
  31. if (type == "flight") {
  32. return Icons.flight_takeoff;
  33. } else if (type == "checkin") {
  34. return Icons.arrow_forward;
  35. } else if (type == "checkout") {
  36. return Icons.arrow_back;
  37. } else if (type == "dhlimo") {
  38. return Icons.airport_shuttle;
  39. } else if (type == "dhflight") {
  40. return Icons.flight_takeoff;
  41. } else if (type == "ground") {
  42. return Icons.folder;
  43. } else if (type == "credit") {
  44. return Icons.schedule;
  45. } else {
  46. return Icons.file_copy;
  47. }
  48. }
  49. compareTo(Duty d) {}
  50. Duty(
  51. {required this.date,
  52. required this.type,
  53. required this.data,
  54. this.order = 0});
  55. }
  56. String _addChar(String str, {String char = ":", int pos = 2}) =>
  57. "${str.substring(0, pos)}$char${str.substring(pos, 4)}";