show correct landmark types when fetching from api
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| import 'dart:collection'; | ||||
| import 'dart:developer'; | ||||
|  | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:anyway/structs/landmark.dart'; | ||||
| @@ -21,7 +22,7 @@ class MapWidget extends StatefulWidget { | ||||
|  | ||||
| class _MapWidgetState extends State<MapWidget> { | ||||
|   late GoogleMapController mapController; | ||||
|   // coordinates of Paris | ||||
|  | ||||
|   CameraPosition _cameraPosition = CameraPosition( | ||||
|     target: LatLng(48.8566, 2.3522), | ||||
|     zoom: 11.0, | ||||
| @@ -36,7 +37,7 @@ class _MapWidgetState extends State<MapWidget> { | ||||
|       CameraUpdate update = CameraUpdate.newLatLng(LatLng(newLocation[0], newLocation[1])); | ||||
|       controller.moveCamera(update); | ||||
|     } | ||||
|     // addLandmarkMarker(); | ||||
|     setMapMarkers(); | ||||
|   } | ||||
|  | ||||
|   void _onCameraIdle() { | ||||
| @@ -44,45 +45,37 @@ class _MapWidgetState extends State<MapWidget> { | ||||
|   } | ||||
|  | ||||
|  | ||||
|   void addLandmarkMarker() async { | ||||
|     LinkedList<Landmark>? landmarks = widget.trip?.landmarks; | ||||
|     int i = mapMarkers.length; | ||||
|     Landmark? current = landmarks!.elementAtOrNull(i); | ||||
|     if (current != null){ | ||||
|       mapMarkers.add( | ||||
|         Marker( | ||||
|           markerId: MarkerId(current.name), | ||||
|           position: LatLng(current.location[0], current.location[1]), | ||||
|           icon: await CustomMarker( | ||||
|             landmark: current, | ||||
|             position: i+1 | ||||
|           ).toBitmapDescriptor( | ||||
|             logicalSize: const Size(150, 150), | ||||
|             imageSize: const Size(150, 150) | ||||
|           ) | ||||
|         ) | ||||
|   void setMapMarkers() async { | ||||
|     List<Landmark> landmarks = widget.trip?.landmarks.toList() ?? []; | ||||
|     Set<Marker> newMarkers = <Marker>{}; | ||||
|     for (int i = 0; i < landmarks.length; i++) { | ||||
|       Landmark landmark = landmarks[i]; | ||||
|       List<double> location = landmark.location; | ||||
|       Marker marker = Marker( | ||||
|         markerId: MarkerId(landmark.uuid), | ||||
|         position: LatLng(location[0], location[1]), | ||||
|         icon: await CustomMarker(landmark: landmark, position: i).toBitmapDescriptor( | ||||
|           logicalSize: const Size(150, 150), | ||||
|           imageSize: const Size(150, 150) | ||||
|         ), | ||||
|       ); | ||||
|       setState(() {}); | ||||
|       newMarkers.add(marker); | ||||
|     } | ||||
|     setState(() { | ||||
|       mapMarkers = newMarkers; | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return ListenableBuilder( | ||||
|       listenable: widget.trip!, | ||||
|       builder: (context, child) { | ||||
|         addLandmarkMarker(); | ||||
|         return GoogleMap( | ||||
|           onMapCreated: _onMapCreated, | ||||
|           initialCameraPosition: _cameraPosition, | ||||
|           onCameraIdle: _onCameraIdle, | ||||
|            | ||||
|           // onLongPress: , | ||||
|           markers: mapMarkers, | ||||
|           cloudMapId: '41c21ac9b81dbfd8', | ||||
|         ); | ||||
|       } | ||||
|     widget.trip?.addListener(setMapMarkers); | ||||
|     return GoogleMap( | ||||
|       onMapCreated: _onMapCreated, | ||||
|       initialCameraPosition: _cameraPosition, | ||||
|       onCameraIdle: _onCameraIdle, | ||||
|       // onLongPress: , | ||||
|       markers: mapMarkers, | ||||
|       cloudMapId: '41c21ac9b81dbfd8', | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| @@ -103,20 +96,34 @@ class CustomMarker extends StatelessWidget { | ||||
|     // This returns an outlined circle, with an icon corresponding to the landmark type | ||||
|     // As a small dot, the number of the landmark is displayed in the top right | ||||
|     Icon icon; | ||||
|     if (landmark.type == museum) { | ||||
|       icon = Icon(Icons.museum, color: Colors.black, size: 50); | ||||
|     } else if (landmark.type == monument) { | ||||
|     if (landmark.type == sightseeing) { | ||||
|       icon = Icon(Icons.church, color: Colors.black, size: 50); | ||||
|     } else if (landmark.type == park) { | ||||
|     } else if (landmark.type == nature) { | ||||
|       icon = Icon(Icons.park, color: Colors.black, size: 50); | ||||
|     } else if (landmark.type == restaurant) { | ||||
|       icon = Icon(Icons.restaurant, color: Colors.black, size: 50); | ||||
|     } else if (landmark.type == shop) { | ||||
|     } else if (landmark.type == shopping) { | ||||
|       icon = Icon(Icons.shopping_cart, color: Colors.black, size: 50); | ||||
|     } else if (landmark.type == start || landmark.type == finish) { | ||||
|       icon = Icon(Icons.flag, color: Colors.black, size: 50); | ||||
|     } else { | ||||
|       icon = Icon(Icons.location_on, color: Colors.black, size: 50); | ||||
|     } | ||||
|  | ||||
|     Widget? positionIndicator; | ||||
|     if (landmark.type != start && landmark.type != finish) { | ||||
|       positionIndicator = Positioned( | ||||
|         top: 0, | ||||
|         right: 0, | ||||
|         child: Container( | ||||
|           padding: EdgeInsets.all(5), | ||||
|           decoration: BoxDecoration( | ||||
|             color: Theme.of(context).primaryColor, | ||||
|             shape: BoxShape.circle, | ||||
|           ), | ||||
|           child: Text('$position', style: TextStyle(color: Colors.white, fontSize: 20)), | ||||
|         ), | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     return RepaintBoundary( | ||||
|       child: Stack( | ||||
|         children: [ | ||||
| @@ -136,18 +143,7 @@ class CustomMarker extends StatelessWidget { | ||||
|             ), | ||||
|             child: icon, | ||||
|           ), | ||||
|           Positioned( | ||||
|             top: 0, | ||||
|             right: 0, | ||||
|             child: Container( | ||||
|               padding: EdgeInsets.all(5), | ||||
|               decoration: BoxDecoration( | ||||
|                 color: Theme.of(context).primaryColor, | ||||
|                 shape: BoxShape.circle, | ||||
|               ), | ||||
|               child: Text('$position', style: TextStyle(color: Colors.white, fontSize: 20)), | ||||
|             ), | ||||
|           ), | ||||
|           positionIndicator ?? Container(), | ||||
|         ], | ||||
|       ), | ||||
|     ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user