@@ -39,6 +39,7 @@ class _MarkersPageState extends ExamplePageState<MarkersPage> {
3939
4040 late bool _isMapToolbarEnabled = true ;
4141 late bool _displayMarkerUpdates = false ;
42+ String _latestMarkerDragUpdate = '' ;
4243 final List <double > _zIndexes = < double > [- 1 , 0 , 1 ];
4344 final List <double > _alphas = < double > [1.0 , 0.3 ];
4445
@@ -215,15 +216,30 @@ class _MarkersPageState extends ExamplePageState<MarkersPage> {
215216 }
216217
217218 void _onMarkerDrag (String markerId, LatLng position) {
218- showMessage ('Marker drag, position: $position markerId: $markerId ' );
219+ if (_displayMarkerUpdates) {
220+ setState (() {
221+ _latestMarkerDragUpdate =
222+ 'Dragging\n Marker: $markerId \n Lat: ${position .latitude .toStringAsFixed (4 )}\n Lng: ${position .longitude .toStringAsFixed (4 )}' ;
223+ });
224+ }
219225 }
220226
221227 void _onMarkerDragStart (String markerId, LatLng position) {
222- showMessage ('Marker drag, position: $position markerId: $markerId ' );
228+ if (_displayMarkerUpdates) {
229+ setState (() {
230+ _latestMarkerDragUpdate =
231+ 'Drag started\n Marker: $markerId \n Lat: ${position .latitude .toStringAsFixed (4 )}\n Lng: ${position .longitude .toStringAsFixed (4 )}' ;
232+ });
233+ }
223234 }
224235
225236 void _onMarkerDragEnd (String markerId, LatLng position) {
226- showMessage ('Marker drag, position: $position markerId: $markerId ' );
237+ if (_displayMarkerUpdates) {
238+ setState (() {
239+ _latestMarkerDragUpdate =
240+ 'Drag ended\n Marker: $markerId \n Lat: ${position .latitude .toStringAsFixed (4 )}\n Lng: ${position .longitude .toStringAsFixed (4 )}' ;
241+ });
242+ }
227243 final Marker marker = _markers.firstWhere (
228244 (Marker marker) => marker.markerId == markerId,
229245 );
@@ -252,17 +268,47 @@ class _MarkersPageState extends ExamplePageState<MarkersPage> {
252268 child: Column (
253269 children: < Widget > [
254270 Expanded (
255- child: GoogleMapsNavigationView (
256- onViewCreated: _onViewCreated,
257- initialNavigationUIEnabledPreference:
258- NavigationUIEnabledPreference .disabled,
259- onMarkerClicked: _onMarkerClicked,
260- onMarkerDrag: _onMarkerDrag,
261- onMarkerDragStart: _onMarkerDragStart,
262- onMarkerDragEnd: _onMarkerDragEnd,
263- onMarkerInfoWindowClicked: _onMarkerInfoWindowClicked,
264- onMarkerInfoWindowClosed: _onMarkerInfoWindowClosed,
265- onMarkerInfoWindowLongClicked: _onMarkerInfoWindowLongClicked,
271+ child: Stack (
272+ children: < Widget > [
273+ GoogleMapsNavigationView (
274+ onViewCreated: _onViewCreated,
275+ initialNavigationUIEnabledPreference:
276+ NavigationUIEnabledPreference .disabled,
277+ onMarkerClicked: _onMarkerClicked,
278+ onMarkerDrag: _onMarkerDrag,
279+ onMarkerDragStart: _onMarkerDragStart,
280+ onMarkerDragEnd: _onMarkerDragEnd,
281+ onMarkerInfoWindowClicked: _onMarkerInfoWindowClicked,
282+ onMarkerInfoWindowClosed: _onMarkerInfoWindowClosed,
283+ onMarkerInfoWindowLongClicked: _onMarkerInfoWindowLongClicked,
284+ ),
285+ if (_displayMarkerUpdates && _latestMarkerDragUpdate.isNotEmpty)
286+ Positioned (
287+ top: 10 ,
288+ left: 10 ,
289+ child: Container (
290+ padding: const EdgeInsets .all (12 ),
291+ decoration: BoxDecoration (
292+ color: Colors .white,
293+ borderRadius: BorderRadius .circular (8 ),
294+ boxShadow: < BoxShadow > [
295+ BoxShadow (
296+ color: Colors .black.withOpacity (0.2 ),
297+ blurRadius: 6 ,
298+ offset: const Offset (0 , 2 ),
299+ ),
300+ ],
301+ ),
302+ child: Text (
303+ _latestMarkerDragUpdate,
304+ style: const TextStyle (
305+ fontSize: 13 ,
306+ fontWeight: FontWeight .w500,
307+ ),
308+ ),
309+ ),
310+ ),
311+ ],
266312 ),
267313 ),
268314 const SizedBox (height: 10 ),
0 commit comments