Reputation: 21
Tell me, how can I not just add a button to the center of the screen once, but move it along with the newCameraPosition parameter?
At the moment, the usual Yandex map display with zoom in and zoom out buttons is implemented, it may be worth somehow making the dependence of the new label on the CameraPosition position in the _onMapCreated method
@override
Widget build(BuildContext context) {
setState(() {
mapObjects.addAll(placemarks);
});
return Stack(
children: [
YandexMap(
mapObjects: mapObjects,
onMapCreated: _onMapCreated,
),
Center(
child: Padding(
padding: const EdgeInsets.only(right: 11),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 97,
width: 40,
decoration: const BoxDecoration(
color: CupertinoColors.white,
borderRadius: BorderRadius.all(Radius.circular(11)),
),
child: Column(
children: [
IconButton(onPressed: () {
_zoomIn();
}, icon: const Icon(Icons.add)),
IconButton(onPressed: () {
_zoomOut();
}, icon: const Icon(Icons.remove)),
],
),
)
],
),
),
)
]
);
}
Future<void> _onMapCreated(YandexMapController controller) async {
_completer.complete(controller);
await controller.moveCamera(CameraUpdate.newCameraPosition(
const CameraPosition(
target: Point(
latitude: 55.755864,
longitude: 37.617698,
),
zoom: 12,
),), animation: const MapAnimation(type: MapAnimationType.linear, duration: 1),);
}
Future<void> _zoomIn() async {
YandexMapController controller = await _completer.future;
controller.moveCamera(CameraUpdate.zoomIn(), animation: MapAnimation(duration: 1, type: MapAnimationType.smooth));
}
Future<void> _zoomOut() async {
YandexMapController controller = await _completer.future;
controller.moveCamera(CameraUpdate.zoomOut(), animation: MapAnimation(duration: 1, type: MapAnimationType.smooth));
}
}
Upvotes: 1
Views: 802