location_convert_marker_util.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter_map/flutter_map.dart';
  2. import 'package:location/data/bean/user_info.dart';
  3. import 'package:location/data/consts/constants.dart';
  4. class Location2MarkerUtil {
  5. Location2MarkerUtil._();
  6. static Marker userInfo2Marker(UserInfo e, bool isSelected, int? electric) {
  7. final marker = Marker(
  8. id: e.id,
  9. markerName: e.getUserNickName(),
  10. longitude: e.lastLocation.value?.longitude,
  11. latitude: e.lastLocation.value?.latitude,
  12. markerType: e.id == Constants.mineLocationId
  13. ? MarkerType.mine
  14. : MarkerType.friend,
  15. isSelected: isSelected,
  16. customAvatarUrl: e.avatar,
  17. );
  18. if (electric != null) {
  19. marker.tags = {'electric': electric};
  20. }
  21. return marker;
  22. }
  23. static List<Marker> userInfoList2MarkerList(List<UserInfo> list,
  24. bool isMemberExpired, UserInfo? selectedFriend,
  25. {int? electric}) {
  26. List<Marker> markers = [];
  27. for (var e in list) {
  28. if (e.isMine == true) {
  29. markers.add(userInfo2Marker(e, e.id == selectedFriend?.id, electric));
  30. } else if (e.blockedMe != true &&
  31. e.lastLocation.value?.longitude != null &&
  32. e.lastLocation.value?.latitude != null &&
  33. !isMemberExpired) {
  34. markers.add(userInfo2Marker(e, e.id == selectedFriend?.id, electric));
  35. }
  36. }
  37. return markers;
  38. }
  39. }