w_lidoofp.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:flutter/material.dart';
  2. import 'package:gap/gap.dart';
  3. import 'package:jiffy/jiffy.dart';
  4. import 'package:tp5/lido/model/Lidoapi_ofp.dart';
  5. import 'package:tp5/widgets/my_row.dart';
  6. class WLidoOfp extends StatelessWidget {
  7. const WLidoOfp({super.key, required this.lidoapiofp, this.onTap});
  8. final LidoapiOfp lidoapiofp;
  9. final dynamic onTap;
  10. Map<String, dynamic> get categories =>
  11. lidoapiofp.categoriesNames?.toJson() ?? {};
  12. @override
  13. Widget build(BuildContext context) {
  14. return InkWell(
  15. onTap: onTap,
  16. child: Column(children: [
  17. ...lidoapiofp.briefingPackages.map((brief) => Card(
  18. color: Colors.grey[900],
  19. shape: RoundedRectangleBorder(
  20. borderRadius: BorderRadius.circular(6.0),
  21. ),
  22. elevation: 8.0,
  23. margin:
  24. const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  25. child: Padding(
  26. padding: const EdgeInsets.all(8.0),
  27. child: Column(children: [
  28. MyRow(children: [
  29. ...brief.leg.map((leg) => Column(children: [
  30. MyRow(children: [
  31. const Text("Schedule:"),
  32. _titleInfo(
  33. "Schedule",
  34. "${Jiffy.parseFromMillisecondsSinceEpoch(leg.scheduledDepartureTime ?? 0).format(pattern: "Hm")}-${Jiffy.parseFromMillisecondsSinceEpoch(leg.scheduledTimeOfArrival ?? 0).format(pattern: "Hm")}",
  35. Jiffy.parseFromMillisecondsSinceEpoch(
  36. leg.scheduledDepartureTime ?? 0)
  37. .format(pattern: "dd MMMyy")),
  38. const Gap(15),
  39. _titleInfo(
  40. "Estimate",
  41. "${Jiffy.parseFromMillisecondsSinceEpoch(leg.estimatedDepartureTime ?? 0).format(pattern: "Hm")}-${Jiffy.parseFromMillisecondsSinceEpoch(leg.estimatedTimeOfArrival ?? 0).format(pattern: "Hm")}",
  42. Jiffy.parseFromMillisecondsSinceEpoch(
  43. leg.estimatedDepartureTime ?? 0)
  44. .format(pattern: "dd MMMyy")),
  45. const Gap(15),
  46. _titleInfo(
  47. "CTOT",
  48. Jiffy.parseFromMillisecondsSinceEpoch(
  49. leg.ctot ?? 0)
  50. .format(pattern: "Hm"),
  51. Jiffy.parseFromMillisecondsSinceEpoch(
  52. leg.ctot ?? 0)
  53. .format(pattern: "dd MMMyy")),
  54. ]),
  55. ]))
  56. ]),
  57. ])),
  58. ))
  59. ]),
  60. );
  61. }
  62. _titleInfo(String? title, String? info, String? secondary,
  63. {double sizetitle = 10,
  64. double sizeinfo = 16,
  65. Color color = Colors.blueGrey,
  66. bool bold = false}) =>
  67. Column(
  68. children: [
  69. Text(
  70. title ?? "---",
  71. style: TextStyle(color: Colors.grey, fontSize: sizetitle),
  72. ),
  73. Text(info ?? "---",
  74. style: TextStyle(
  75. color: color,
  76. fontSize: sizeinfo,
  77. fontWeight: bold ? FontWeight.bold : null)),
  78. if (secondary != null)
  79. Text(secondary == "" ? "---" : secondary,
  80. style: TextStyle(
  81. color: color,
  82. fontSize: sizeinfo - 4,
  83. fontWeight: bold ? FontWeight.w700 : null)),
  84. ],
  85. );
  86. kilo2ton(int? k, {bool ceil = true}) {
  87. if (k == null) return null;
  88. const double conversionFactor = 0.001;
  89. double tons = k * conversionFactor;
  90. if (ceil) {
  91. return "${double.parse(((tons * 10).ceilToDouble() / 10).toStringAsFixed(1))}T";
  92. } else {
  93. return "${double.parse(((tons * 10).floorToDouble() / 10).toStringAsFixed(1))}T";
  94. }
  95. }
  96. }