import 'package:common_pub/logger.dart'; import 'package:common_pub/service/controller.dart'; import 'package:common_pub/ui/map_view/map_view.dart'; import 'package:common_pub/ui/map_view/view_map_trace.dart'; import 'package:track_common/model.dart'; class Flag { Flag(this.value); int value; Color get color => Color(value); @override bool operator ==(Object other) { if (other is Flag) { return value == other.value; } return false; } @override int get hashCode => value.hashCode; static final red = Flag(0xffff0000); static final yellow = Flag(0xffffcb00); static final blue = Flag(0xff00a0ff); static List get values => [red, yellow, blue]; } class UserOnMap { var info = UserInfo(); int get id => info.id; String get name => info.name; var startAt = DateTime.now(); var cpList = []; final isHide = false.obs; var trace = [].obs; var flag = Flag.red.obs; String routeName = ''; int heartRatePercent = 0; Pace pace = Pace.perKm(99.hours); var distance = 0.km; List hrInfo = []; List positionList = []; Duration get duration => DateTime.now().difference(startAt); ControlPoint? nextWant; Distance get nextDistance { final one = nextWant; if (one != null) { final p1 = one.position; final p22 = positionList.lastOrNull; if (p22 != null) { return p1.distance(p22); } } return const Distance(m: 1000); } String get nextCPSN { return nextWant?.snString ?? ''; } } class EventOnMap { var info = EventInfo(); var userList = []; int get id => info.id; String get name => info.name; int get cpAllCount => info.cpAllCount; final isHide = false.obs; } abstract class MapWatchService extends GetxService { final Rx _instance = Rx(null); MapWatch? get instance => _instance.value; @protected Future newInstanceByMap(MapInfo info); Future setMap(MapInfo mapInfo) async { final thisInstance = await newInstanceByMap(mapInfo); thisInstance.addPlugs([thisInstance.plugMap]); _instance.value = thisInstance; thisInstance.init(); thisInstance.workFlushData(); } } abstract class MapWatch extends PlugController { Future workFlushData() async { while (isActive) { try { // await flushData(); } catch (e) { error(e); } await 1.seconds.delay(); } } EventOnMap? getEventById(int id) { for (final one in eventList) { if (one.id == id) { return one; } } return null; } MapWatch({required this.id}); final int id; String name = ''; final plugMap = PlugMap(); final eventList = [].obs; @protected Future> getEventList(int mapId); }