field_control.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. import 'package:application/service/api.dart' as pb;
  2. import 'package:application/widget.dart';
  3. import 'package:common_pub/ui/map_view/map_view.dart';
  4. import 'package:common_pub/ui/map_view/view_map_cp.dart';
  5. import 'package:common_pub/ui/map_view/view_map_image.dart';
  6. import 'package:common_pub/ui/map_view/view_map_trace_tail.dart';
  7. import 'package:common_pub/ui/map_view/view_map_touch.dart';
  8. import 'package:common_pub/ui/map_view/view_map_user_point.dart';
  9. import 'package:common_pub/ui/map_view/view_plug_loading.dart';
  10. import 'package:common_pub/utils.dart';
  11. import 'field_control_controller.dart';
  12. class FieldControlPage extends StatelessWidget {
  13. const FieldControlPage({super.key});
  14. @override
  15. Widget build(BuildContext context) {
  16. return GetBuilder(
  17. init: FieldControlController(),
  18. builder: (c) {
  19. return Container(
  20. height: double.infinity,
  21. width: double.infinity,
  22. color: const Color(0xffc9c0c0),
  23. alignment: Alignment.center,
  24. child: Obx(() {
  25. final mapWatch = c.mapWatch;
  26. return mapWatch != null
  27. ? content(context, mapWatch, c)
  28. : noData();
  29. }));
  30. });
  31. }
  32. Widget noData() {
  33. return Center(
  34. child: Column(
  35. mainAxisSize: MainAxisSize.min,
  36. children: [
  37. Image.asset(Assets.imagesIcNoData, height: 64),
  38. const SizedBox(height: 25),
  39. const Text('没有数据, 请选择地图',
  40. style: TextStyle(color: Color(0xff707070), fontSize: 18.5)),
  41. ],
  42. ),
  43. );
  44. }
  45. Widget content(
  46. BuildContext context, MapWatchService map, FieldControlController c) {
  47. final children = <Widget>[
  48. ViewPlugLoading(map.plugMap),
  49. ViewMapImage(map.plugMap),
  50. ];
  51. final focusUser = c.focusUser.value;
  52. if (focusUser != null) {
  53. children.add(ViewMapCP(
  54. map.plugMap,
  55. cpWantAndHistoryList: focusUser.cpList,
  56. isHideRouteBeforeStart: false,
  57. ));
  58. }
  59. children.addAll([
  60. _ViewTrace(map: map, traceDuration: 30.seconds),
  61. ViewMapTouch(map.plugMap)
  62. ]);
  63. return Row(
  64. children: [
  65. Expanded(
  66. child: Column(
  67. children: [
  68. Expanded(
  69. child: ViewMapStack(plug: map.plugMap, children: children)),
  70. _MsgView(),
  71. ],
  72. )),
  73. _ActiveInfoView()
  74. ],
  75. );
  76. }
  77. }
  78. class _ViewTrace extends GetView<FieldControlController> {
  79. const _ViewTrace({required this.map, required this.traceDuration});
  80. final MapWatchService map;
  81. final Duration traceDuration;
  82. @override
  83. Widget build(BuildContext context) {
  84. return Obx(() {
  85. final children = <Widget>[];
  86. for (final act in map.activeList) {
  87. for (final user in act.userList) {
  88. if (user.isHide.value) {
  89. continue;
  90. }
  91. final trace = user.trace.lastOrNull;
  92. final traceTailOnMap = <Offset>[];
  93. final st = user.gameInfo.gameSaveInfo.startAt.toModel();
  94. for (final one in user.trace) {
  95. if (DateTime.now().difference(st.add(one.ts)) < traceDuration) {
  96. traceTailOnMap.add(one.onMap);
  97. }
  98. }
  99. if (trace != null) {
  100. children.add(ViewMapTraceTail(
  101. plug: map.plugMap,
  102. onMapTrace: traceTailOnMap,
  103. color: user.flag.value.color,
  104. ));
  105. children.add(ViewMapUserPoint(
  106. key: UniqueKey(),
  107. map.plugMap, trace,
  108. info: user.name, color: user.flag.value.color));
  109. }
  110. }
  111. }
  112. return Stack(alignment: Alignment.topLeft, children: children);
  113. });
  114. }
  115. }
  116. class _ActiveInfoView extends GetView<FieldControlController> {
  117. @override
  118. Widget build(BuildContext context) {
  119. return Obx(() => Container(
  120. width: 370,
  121. height: double.infinity,
  122. color: Colors.white,
  123. child: ListView(
  124. children: controller.activeList
  125. .map((element) => activeView(element))
  126. .toList(),
  127. ),
  128. ));
  129. }
  130. Widget activeView(ActiveInfo info) {
  131. final children = <Widget>[
  132. Row(children: [
  133. Text('${info.name} (${info.userList.length}人)'),
  134. const Spacer(),
  135. IconButton(
  136. onPressed: () {
  137. info.isHide.value = !info.isHide.value;
  138. },
  139. icon: info.isHide.value
  140. ? const Icon(Icons.arrow_drop_down)
  141. : const Icon(Icons.arrow_drop_up))
  142. ]),
  143. ];
  144. if (!info.isHide.value) {
  145. children.addAll([
  146. Container(
  147. decoration: BoxDecoration(
  148. color: Colors.white, borderRadius: BorderRadius.circular(5)),
  149. padding: const EdgeInsets.fromLTRB(26, 11, 26, 11),
  150. child: Row(
  151. children: [
  152. const Text('广播'),
  153. const Spacer(),
  154. Image.asset(Assets.imagesIcCp, height: 20, width: 20),
  155. Text(' ${info.cpAllCount}'),
  156. const Spacer(),
  157. const Text('全部隐藏'),
  158. ],
  159. ),
  160. )
  161. ]);
  162. children
  163. .addAll(info.userList.map((e) => _UserInfoView(data: e)).toList());
  164. }
  165. return Container(
  166. decoration: BoxDecoration(
  167. color: const Color(0xffe0e0e0),
  168. borderRadius: BorderRadius.circular(5)),
  169. margin: const EdgeInsets.fromLTRB(9, 12, 9, 12),
  170. padding: const EdgeInsets.all(9),
  171. child: Column(
  172. children: children,
  173. ),
  174. );
  175. }
  176. }
  177. class _UserInfoView extends GetView<FieldControlController> {
  178. const _UserInfoView({required this.data});
  179. final UserInfo data;
  180. @override
  181. Widget build(BuildContext context) {
  182. return Container(
  183. decoration: BoxDecoration(
  184. color: Colors.white, borderRadius: BorderRadius.circular(5)),
  185. padding: const EdgeInsets.fromLTRB(7, 11, 7, 11),
  186. margin: const EdgeInsets.only(top: 5),
  187. child: Column(
  188. crossAxisAlignment: CrossAxisAlignment.start,
  189. children: [
  190. Row(
  191. children: [
  192. Obx(() => Container(
  193. margin: const EdgeInsets.only(top: 2),
  194. decoration: BoxDecoration(
  195. color: data.flag.value.color,
  196. borderRadius: BorderRadius.circular(4)),
  197. width: 7,
  198. height: 16)),
  199. const SizedBox(
  200. width: 8,
  201. ),
  202. Expanded(
  203. child: Text.rich(TextSpan(
  204. text: data.name,
  205. children: [TextSpan(text: ' [${data.routeName}]')])),
  206. ),
  207. GestureDetector(
  208. onTap: () {
  209. final old = controller.focusUser.value;
  210. if(old != null){
  211. if(old.id == data.id){
  212. controller.focusUser.value = null;
  213. return;
  214. }
  215. }
  216. controller.focusUser.value = data;
  217. },
  218. child: Obx(() => Icon(
  219. Icons.route,
  220. color: data.gameInfo.userId !=
  221. controller.focusUser.value?.gameInfo.userId
  222. ? Colors.grey
  223. : const Color(0xffffbb77),
  224. )),
  225. ),
  226. const SizedBox(width: 8),
  227. GestureDetector(
  228. onTap: () {
  229. data.isHide.value = !data.isHide.value;
  230. },
  231. child: Obx(() => Icon(
  232. data.isHide.value
  233. ? Icons.visibility_off
  234. : Icons.visibility,
  235. color: data.isHide.value
  236. ? Colors.grey
  237. : const Color(0xffffbb77),
  238. )),
  239. )
  240. ],
  241. ),
  242. Container(
  243. margin: const EdgeInsets.only(left: 14),
  244. child: Row(
  245. children: [
  246. container(null, cpInfo, Colors.blue),
  247. container(
  248. const Icon(
  249. Icons.favorite,
  250. size: 13,
  251. color: Colors.white,
  252. ),
  253. ' ${hr == 0 ? '--' : hr}',
  254. (data.gameInfo.otherInfo.hasHeartRatePercent()
  255. ? data.gameInfo.otherInfo.heartRatePercent
  256. : 0)
  257. .toHRPColor()),
  258. container(null, paceInfo, data.pace.color)
  259. ],
  260. ),
  261. ),
  262. const SizedBox(height: 5),
  263. Container(
  264. margin: const EdgeInsets.only(left: 14),
  265. child: Row(
  266. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  267. children: [
  268. Text('距离 ${data.nextDistance.toString()}'),
  269. Text('时间 ${data.duration.toAppString()}'),
  270. Text('里程 ${data.distance.toString()}'),
  271. ],
  272. ))
  273. ],
  274. ),
  275. );
  276. }
  277. int get hr {
  278. return data.gameInfo.hrInfo.hrInfo.lastOrNull?.hr ?? 0;
  279. }
  280. String get cpInfo {
  281. final next = data.nextWant;
  282. return next != null ? '${data.nextCPSN}点(${next.areaId})' : '--';
  283. }
  284. String get paceInfo {
  285. Duration;
  286. return data.pace.toString();
  287. }
  288. Widget container(Widget? icon, String text, Color color) {
  289. final children = <Widget>[];
  290. if (icon != null) {
  291. children.add(icon);
  292. }
  293. children.add(
  294. Text(text, style: const TextStyle(color: Colors.white, fontSize: 14)));
  295. return Container(
  296. height: 20,
  297. padding: const EdgeInsets.fromLTRB(10, 0, 12, 0),
  298. margin: const EdgeInsets.only(right: 6),
  299. alignment: Alignment.center,
  300. decoration:
  301. BoxDecoration(color: color, borderRadius: BorderRadius.circular(9)),
  302. child: Row(
  303. children: children,
  304. ),
  305. );
  306. }
  307. }
  308. class _MsgView extends GetView<FieldControlController> {
  309. @override
  310. Widget build(BuildContext context) {
  311. return Container();
  312. }
  313. }