@@ -37,6 +37,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
3737 Map <AnnotationId , Annotation > annotations = < AnnotationId , Annotation > {};
3838 AnnotationId selectedAnnotation;
3939 int _annotationIdCounter = 1 ;
40+ BitmapDescriptor _annotationIcon;
4041
4142 void _onMapCreated (AppleMapController controller) {
4243 this .controller = controller;
@@ -52,8 +53,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
5253 if (tappedAnnotation != null ) {
5354 setState (() {
5455 if (annotations.containsKey (selectedAnnotation)) {
55- final Annotation resetOld = annotations[selectedAnnotation]
56- .copyWith (iconParam : BitmapDescriptor .defaultAnnotation );
56+ final Annotation resetOld =
57+ annotations[selectedAnnotation] .copyWith ();
5758 annotations[selectedAnnotation] = resetOld;
5859 }
5960 selectedAnnotation = annotationId;
@@ -76,12 +77,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
7677 annotationId: annotationId,
7778 icon: iconType == 'marker'
7879 ? BitmapDescriptor .markerAnnotation
79- : BitmapDescriptor .defaultAnnotation,
80+ : iconType == 'pin'
81+ ? BitmapDescriptor .defaultAnnotation
82+ : _annotationIcon,
8083 position: LatLng (
8184 center.latitude + sin (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
8285 center.longitude + cos (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
8386 ),
84- infoWindow: InfoWindow (title: annotationIdVal, snippet: '*' ),
87+ infoWindow: InfoWindow (
88+ title: annotationIdVal,
89+ snippet: '*' ,
90+ onTap: () => print ('InfowWindow of id: $annotationId tapped.' )),
8591 onTap: () {
8692 _onAnnotationTapped (annotationId);
8793 },
@@ -128,7 +134,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
128134
129135 Future <void > _changeInfo () async {
130136 final Annotation annotation = annotations[selectedAnnotation];
131- final String newSnippet = annotation.infoWindow.snippet + '*' ;
137+ final String newSnippet = annotation.infoWindow.snippet +
138+ (annotation.infoWindow.snippet.length % 10 == 0 ? '\n ' : '*' );
132139 setState (() {
133140 annotations[selectedAnnotation] = annotation.copyWith (
134141 infoWindowParam: annotation.infoWindow.copyWith (
@@ -157,8 +164,44 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
157164 });
158165 }
159166
167+ Future <void > _createAnnotationImageFromAsset (BuildContext context) async {
168+ if (_annotationIcon == null ) {
169+ final ImageConfiguration imageConfiguration =
170+ createLocalImageConfiguration (context);
171+ BitmapDescriptor .fromAssetImage (
172+ imageConfiguration, 'assets/red_square.png' )
173+ .then (_updateBitmap);
174+ }
175+ }
176+
177+ void _updateBitmap (BitmapDescriptor bitmap) {
178+ setState (() {
179+ _annotationIcon = bitmap;
180+ });
181+ }
182+
183+ Future <void > _showInfoWindow () async {
184+ final Annotation annotation = annotations[selectedAnnotation];
185+ await this .controller.showMarkerInfoWindow (annotation.annotationId);
186+ }
187+
188+ Future <void > _hideInfoWindow () async {
189+ final Annotation annotation = annotations[selectedAnnotation];
190+ this .controller.hideMarkerInfoWindow (annotation.annotationId);
191+ }
192+
193+ Future <bool > _isInfoWindowShown () async {
194+ final Annotation annotation = annotations[selectedAnnotation];
195+ print (
196+ 'Is InfowWindow visible: ${await this .controller .isMarkerInfoWindowShown (annotation .annotationId )}' );
197+ return await this
198+ .controller
199+ .isMarkerInfoWindowShown (annotation.annotationId);
200+ }
201+
160202 @override
161203 Widget build (BuildContext context) {
204+ _createAnnotationImageFromAsset (context);
162205 return Column (
163206 mainAxisAlignment: MainAxisAlignment .spaceEvenly,
164207 crossAxisAlignment: CrossAxisAlignment .stretch,
@@ -194,6 +237,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
194237 child: const Text ('add markerAnnotation' ),
195238 onPressed: () => _add ('marker' ),
196239 ),
240+ FlatButton (
241+ child: const Text ('add customAnnotation' ),
242+ onPressed: () => _add ('customAnnotation' ),
243+ ),
197244 FlatButton (
198245 child: const Text ('remove' ),
199246 onPressed: _remove,
@@ -202,6 +249,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
202249 child: const Text ('change info' ),
203250 onPressed: _changeInfo,
204251 ),
252+ FlatButton (
253+ child: const Text ('infoWindow is shown?s' ),
254+ onPressed: _isInfoWindowShown,
255+ ),
205256 ],
206257 ),
207258 Column (
@@ -222,6 +273,14 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
222273 child: const Text ('toggle visible' ),
223274 onPressed: _toggleVisible,
224275 ),
276+ FlatButton (
277+ child: const Text ('show infoWindow' ),
278+ onPressed: _showInfoWindow,
279+ ),
280+ FlatButton (
281+ child: const Text ('hide infoWindow' ),
282+ onPressed: _hideInfoWindow,
283+ ),
225284 ],
226285 ),
227286 ],
0 commit comments