2023-12-10 16:37:32 +00:00
|
|
|
import "package:flutter/material.dart";
|
|
|
|
import "package:flutter_map/flutter_map.dart";
|
2023-12-10 17:36:07 +00:00
|
|
|
import "package:latlong2/latlong.dart";
|
2023-12-10 16:37:32 +00:00
|
|
|
import "package:photos/ui/map/map_button.dart";
|
|
|
|
import "package:photos/ui/map/tile/layers.dart";
|
|
|
|
|
|
|
|
class AddLocationDataWidget extends StatefulWidget {
|
|
|
|
const AddLocationDataWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AddLocationDataWidget> createState() => _AddLocationDataWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddLocationDataWidgetState extends State<AddLocationDataWidget> {
|
|
|
|
final MapController _mapController = MapController();
|
2023-12-10 17:36:07 +00:00
|
|
|
ValueNotifier<LatLng?> selectedLocation = ValueNotifier(null);
|
2023-12-10 16:37:32 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
2023-12-10 17:36:07 +00:00
|
|
|
selectedLocation.dispose();
|
|
|
|
|
2023-12-10 16:37:32 +00:00
|
|
|
_mapController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
FlutterMap(
|
|
|
|
mapController: _mapController,
|
|
|
|
options: MapOptions(
|
|
|
|
zoom: 3,
|
|
|
|
maxZoom: 18.0,
|
|
|
|
minZoom: 2.8,
|
|
|
|
onTap: (tapPosition, latlng) {
|
2023-12-10 17:36:07 +00:00
|
|
|
final zoom = selectedLocation.value == null
|
|
|
|
? _mapController.zoom + 2.0
|
|
|
|
: _mapController.zoom;
|
|
|
|
_mapController.move(latlng, zoom);
|
|
|
|
|
|
|
|
selectedLocation.value = latlng;
|
|
|
|
},
|
|
|
|
onPositionChanged: (position, hasGesture) {
|
|
|
|
if (selectedLocation.value != null) {
|
|
|
|
selectedLocation.value = position.center;
|
|
|
|
}
|
2023-12-10 16:37:32 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
children: const [
|
|
|
|
OSMFranceTileLayer(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
// bottom: widget.bottomSheetDraggableAreaHeight + 10,
|
|
|
|
bottom: 30,
|
|
|
|
|
|
|
|
right: 10,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
MapButton(
|
|
|
|
icon: Icons.add,
|
|
|
|
onPressed: () {
|
|
|
|
_mapController.move(
|
|
|
|
_mapController.center,
|
|
|
|
_mapController.zoom + 1,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
heroTag: 'zoom-in',
|
|
|
|
),
|
|
|
|
MapButton(
|
|
|
|
icon: Icons.remove,
|
|
|
|
onPressed: () {
|
|
|
|
_mapController.move(
|
|
|
|
_mapController.center,
|
|
|
|
_mapController.zoom - 1,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
heroTag: 'zoom-out',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-12-10 17:36:07 +00:00
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable: selectedLocation,
|
|
|
|
builder: (context, value, _) {
|
|
|
|
return value != null
|
|
|
|
? const Positioned(
|
|
|
|
bottom: 20,
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: Icon(
|
|
|
|
Icons.location_pin,
|
|
|
|
color: Color.fromARGB(255, 250, 34, 19),
|
|
|
|
size: 40,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable: selectedLocation,
|
|
|
|
builder: (context, value, _) {
|
|
|
|
return value != null
|
|
|
|
? Positioned(
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
selectedLocation.value.toString(),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink();
|
|
|
|
},
|
|
|
|
),
|
2023-12-10 16:37:32 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|