@@ -37,8 +37,9 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
3737 static final LatLng center = const LatLng (- 33.86711 , 151.1947171 );
3838
3939 late AppleMapController controller;
40+ Uint8List ? _imageBytes;
4041 Map <AnnotationId , Annotation > annotations = < AnnotationId , Annotation > {};
41- late AnnotationId selectedAnnotation ;
42+ late AnnotationId selectedAnnotationId ;
4243 int _annotationIdCounter = 1 ;
4344 BitmapDescriptor ? _annotationIcon;
4445 late BitmapDescriptor _iconFromBytes;
@@ -59,10 +60,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
5960 setState (() {
6061 if (annotations.containsKey (tappedAnnotation)) {
6162 final Annotation resetOld =
62- annotations[selectedAnnotation ]! .copyWith ();
63- annotations[selectedAnnotation ] = resetOld;
63+ annotations[selectedAnnotationId ]! .copyWith ();
64+ annotations[selectedAnnotationId ] = resetOld;
6465 }
65- selectedAnnotation = annotationId;
66+ selectedAnnotationId = annotationId;
6667 });
6768 }
6869 }
@@ -91,6 +92,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
9192 center.latitude + sin (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
9293 center.longitude + cos (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
9394 ),
95+ zIndex: annotationCount.toDouble (),
9496 infoWindow: InfoWindow (
9597 title: annotationIdVal,
9698 anchor: Offset (0.5 , 0.0 ),
@@ -108,21 +110,21 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
108110
109111 void _remove () {
110112 setState (() {
111- if (annotations.containsKey (selectedAnnotation )) {
112- annotations.remove (selectedAnnotation );
113+ if (annotations.containsKey (selectedAnnotationId )) {
114+ annotations.remove (selectedAnnotationId );
113115 }
114116 });
115117 }
116118
117119 void _changePosition () {
118- final Annotation annotation = annotations[selectedAnnotation ]! ;
120+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
119121 final LatLng current = annotation.position;
120122 final Offset offset = Offset (
121123 center.latitude - current.latitude,
122124 center.longitude - current.longitude,
123125 );
124126 setState (() {
125- annotations[selectedAnnotation ] = annotation.copyWith (
127+ annotations[selectedAnnotationId ] = annotation.copyWith (
126128 positionParam: LatLng (
127129 center.latitude + offset.dy,
128130 center.longitude + offset.dx,
@@ -132,20 +134,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
132134 }
133135
134136 Future <void > _toggleDraggable () async {
135- final Annotation annotation = annotations[selectedAnnotation ]! ;
137+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
136138 setState (() {
137- annotations[selectedAnnotation ] = annotation.copyWith (
139+ annotations[selectedAnnotationId ] = annotation.copyWith (
138140 draggableParam: ! annotation.draggable,
139141 );
140142 });
141143 }
142144
143145 Future <void > _changeInfo () async {
144- final Annotation annotation = annotations[selectedAnnotation ]! ;
146+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
145147 final String newSnippet = annotation.infoWindow.snippet! +
146148 (annotation.infoWindow.snippet! .length % 10 == 0 ? '\n ' : '*' );
147149 setState (() {
148- annotations[selectedAnnotation ] = annotation.copyWith (
150+ annotations[selectedAnnotationId ] = annotation.copyWith (
149151 infoWindowParam: annotation.infoWindow.copyWith (
150152 snippetParam: newSnippet,
151153 ),
@@ -154,19 +156,19 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
154156 }
155157
156158 Future <void > _changeAlpha () async {
157- final Annotation annotation = annotations[selectedAnnotation ]! ;
159+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
158160 final double current = annotation.alpha;
159161 setState (() {
160- annotations[selectedAnnotation ] = annotation.copyWith (
162+ annotations[selectedAnnotationId ] = annotation.copyWith (
161163 alphaParam: current < 0.1 ? 1.0 : current * 0.75 ,
162164 );
163165 });
164166 }
165167
166168 Future <void > _toggleVisible () async {
167- final Annotation annotation = annotations[selectedAnnotation ]! ;
169+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
168170 setState (() {
169- annotations[selectedAnnotation ] = annotation.copyWith (
171+ annotations[selectedAnnotationId ] = annotation.copyWith (
170172 visibleParam: ! annotation.visible,
171173 );
172174 });
@@ -190,17 +192,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
190192 }
191193
192194 Future <void > _showInfoWindow () async {
193- final Annotation annotation = annotations[selectedAnnotation ]! ;
195+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
194196 await this .controller.showMarkerInfoWindow (annotation.annotationId);
195197 }
196198
197199 Future <void > _hideInfoWindow () async {
198- final Annotation annotation = annotations[selectedAnnotation ]! ;
200+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
199201 this .controller.hideMarkerInfoWindow (annotation.annotationId);
200202 }
201203
202204 Future <bool > _isInfoWindowShown () async {
203- final Annotation annotation = annotations[selectedAnnotation ]! ;
205+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
204206 print (
205207 'Is InfowWindow visible: ${await this .controller .isMarkerInfoWindowShown (annotation .annotationId )}' );
206208 return (await this
@@ -219,10 +221,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
219221 .asUint8List ());
220222 }
221223
224+ Future <void > _changeZIndex (AnnotationId annotationId) async {
225+ final Annotation annotation = annotations[annotationId]! ;
226+ final double current = annotation.zIndex;
227+ setState (() {
228+ annotations[annotationId] = annotation.copyWith (
229+ zIndexParam: current >= 12.0 ? 0.0 : current + 1.0 ,
230+ );
231+ });
232+ }
233+
222234 @override
223235 Widget build (BuildContext context) {
224236 _createAnnotationImageFromAsset (context, _devicePixelRatio);
225- _getBytesFromAsset ('assets/red_square .png' , 40 );
237+ _getBytesFromAsset ('assets/creator .png' , 160 );
226238 return SafeArea (
227239 child: Column (
228240 children: < Widget > [
@@ -293,6 +305,25 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
293305 child: const Text ('hide infoWindow' ),
294306 onPressed: _hideInfoWindow,
295307 ),
308+ TextButton (
309+ child: const Text ('change zIndex' ),
310+ onPressed: () => _changeZIndex (selectedAnnotationId),
311+ ),
312+ TextButton (
313+ child: Text ('Take a snapshot' ),
314+ onPressed: () async {
315+ final imageBytes = await this .controller.takeSnapshot ();
316+ setState (() {
317+ _imageBytes = imageBytes;
318+ });
319+ },
320+ ),
321+ Container (
322+ decoration: BoxDecoration (color: Colors .blueGrey[50 ]),
323+ height: 180 ,
324+ child:
325+ _imageBytes != null ? Image .memory (_imageBytes! ) : null ,
326+ ),
296327 ],
297328 ),
298329 )
0 commit comments