import 'package:custom_info_window/custom_info_window.dart'; import 'package:flutter/cupertino.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:itp_app2/util/custom_info_window.dart'; class MapService { MapService._(); static MapService _instance; static MapService get instance { _instance ??= MapService._(); return _instance; } final String baseUrl = "https://maps.googleapis.com/maps/api/directions/json"; Duration duration = const Duration(milliseconds: 100); ValueNotifier> markers = ValueNotifier>({}); CustomInfoWindowController controller = CustomInfoWindowController(); Marker getSingleMarker(String markerId) { return markers.value.firstWhere((element) => element.markerId == MarkerId(markerId), orElse: () => null); } Future> addMarker(String markerId, LatLng latlng, String imageUrl, String title, BitmapDescriptor descriptor, int attractionId, {@required InfoWindowType type}) async { final marker = Marker( markerId: MarkerId(markerId), position: latlng, icon: descriptor, onTap: () { controller.addInfoWindow( CustomWindow( info: CityCabInfoWindow( name: "$title", position: latlng, type: type, attractionId: attractionId, imageUrl: imageUrl, time: duration, ), ), latlng); }); try { final markerPosition = markers.value.firstWhere((marker) => marker.markerId.value == markerId); markerPosition.copyWith(positionParam: latlng); return markers.value; } catch (e) { markers.value.add(marker); return markers.value; } } }