2023-12-15 16:20:13 +00:00
|
|
|
import "dart:async";
|
|
|
|
|
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-12 10:03:57 +00:00
|
|
|
import "package:photos/models/file/file.dart";
|
2023-12-15 16:20:13 +00:00
|
|
|
import "package:photos/models/location/location.dart";
|
2023-12-12 10:16:34 +00:00
|
|
|
import "package:photos/services/files_service.dart";
|
2023-12-15 16:20:13 +00:00
|
|
|
import "package:photos/services/location_service.dart";
|
|
|
|
import "package:photos/theme/effects.dart";
|
|
|
|
import "package:photos/theme/ente_theme.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";
|
2023-12-15 16:20:13 +00:00
|
|
|
import "package:photos/utils/toast_util.dart";
|
2023-12-10 16:37:32 +00:00
|
|
|
|
2023-12-12 10:03:57 +00:00
|
|
|
class UpdateLocationDataWidget extends StatefulWidget {
|
|
|
|
final List<EnteFile> files;
|
|
|
|
const UpdateLocationDataWidget(this.files, {super.key});
|
2023-12-10 16:37:32 +00:00
|
|
|
|
|
|
|
@override
|
2023-12-12 10:03:57 +00:00
|
|
|
State<UpdateLocationDataWidget> createState() =>
|
|
|
|
_UpdateLocationDataWidgetState();
|
2023-12-10 16:37:32 +00:00
|
|
|
}
|
|
|
|
|
2023-12-12 10:03:57 +00:00
|
|
|
class _UpdateLocationDataWidgetState extends State<UpdateLocationDataWidget> {
|
2023-12-10 16:37:32 +00:00
|
|
|
final MapController _mapController = MapController();
|
2023-12-11 08:11:57 +00:00
|
|
|
ValueNotifier hasSelectedLocation = ValueNotifier(false);
|
2023-12-15 16:20:13 +00:00
|
|
|
final selectedLocation = ValueNotifier<LatLng?>(null);
|
2023-12-15 17:05:13 +00:00
|
|
|
final isDragging = ValueNotifier(false);
|
2023-12-10 16:37:32 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
2023-12-12 10:03:57 +00:00
|
|
|
hasSelectedLocation.dispose();
|
2023-12-15 16:20:13 +00:00
|
|
|
selectedLocation.dispose();
|
2023-12-10 16:37:32 +00:00
|
|
|
_mapController.dispose();
|
2023-12-15 17:05:13 +00:00
|
|
|
isDragging.dispose();
|
2023-12-10 16:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-12-15 16:20:13 +00:00
|
|
|
final textTheme = getEnteTextTheme(context);
|
2023-12-10 16:37:32 +00:00
|
|
|
return Stack(
|
2023-12-15 16:20:13 +00:00
|
|
|
alignment: Alignment.topCenter,
|
2023-12-10 16:37:32 +00:00
|
|
|
children: [
|
|
|
|
FlutterMap(
|
|
|
|
mapController: _mapController,
|
|
|
|
options: MapOptions(
|
2023-12-15 17:05:13 +00:00
|
|
|
enableMultiFingerGestureRace: true,
|
2023-12-10 16:37:32 +00:00
|
|
|
zoom: 3,
|
|
|
|
maxZoom: 18.0,
|
|
|
|
minZoom: 2.8,
|
2023-12-15 17:05:13 +00:00
|
|
|
onMapEvent: (p0) {
|
|
|
|
if (p0.source == MapEventSource.onDrag) {
|
|
|
|
isDragging.value = true;
|
|
|
|
} else if (p0.source == MapEventSource.dragEnd) {
|
|
|
|
isDragging.value = false;
|
|
|
|
}
|
|
|
|
},
|
2023-12-10 16:37:32 +00:00
|
|
|
onTap: (tapPosition, latlng) {
|
2023-12-15 16:20:13 +00:00
|
|
|
final zoom = selectedLocation.value == null
|
2023-12-10 17:36:07 +00:00
|
|
|
? _mapController.zoom + 2.0
|
|
|
|
: _mapController.zoom;
|
|
|
|
_mapController.move(latlng, zoom);
|
|
|
|
|
2023-12-15 16:20:13 +00:00
|
|
|
selectedLocation.value = latlng;
|
2023-12-11 08:11:57 +00:00
|
|
|
hasSelectedLocation.value = true;
|
2023-12-10 17:36:07 +00:00
|
|
|
},
|
|
|
|
onPositionChanged: (position, hasGesture) {
|
2023-12-15 16:20:13 +00:00
|
|
|
if (selectedLocation.value != null) {
|
|
|
|
selectedLocation.value = position.center;
|
2023-12-10 17:36:07 +00:00
|
|
|
}
|
2023-12-10 16:37:32 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
children: const [
|
|
|
|
OSMFranceTileLayer(),
|
|
|
|
],
|
|
|
|
),
|
2023-12-15 16:20:13 +00:00
|
|
|
Positioned(
|
|
|
|
top: 24,
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
vertical: 10,
|
|
|
|
),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
color: getEnteColorScheme(context).backgroundElevated,
|
|
|
|
boxShadow: shadowFloatFaintLight,
|
|
|
|
),
|
|
|
|
child: ValueListenableBuilder(
|
2023-12-15 17:05:13 +00:00
|
|
|
valueListenable: selectedLocation,
|
2023-12-15 16:20:13 +00:00
|
|
|
builder: (context, value, _) {
|
|
|
|
final locationInDMS =
|
|
|
|
LocationService.instance.convertLocationToDMS(
|
|
|
|
Location(
|
|
|
|
latitude: value?.latitude,
|
|
|
|
longitude: value?.longitude,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return locationInDMS != null
|
|
|
|
? SizedBox(
|
|
|
|
width: 80 * MediaQuery.textScaleFactorOf(context),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
locationInDMS[0],
|
|
|
|
style: textTheme.mini,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
locationInDMS[1],
|
|
|
|
style: textTheme.mini,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Text(
|
|
|
|
"Select a location",
|
|
|
|
style: textTheme.mini,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-12-10 16:37:32 +00:00
|
|
|
Positioned(
|
|
|
|
// bottom: widget.bottomSheetDraggableAreaHeight + 10,
|
2023-12-15 16:20:13 +00:00
|
|
|
bottom: 48,
|
2023-12-10 16:37:32 +00:00
|
|
|
|
2023-12-15 16:20:13 +00:00
|
|
|
right: 24,
|
|
|
|
left: 24,
|
2023-12-10 16:37:32 +00:00
|
|
|
child: Column(
|
2023-12-15 16:20:13 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
2023-12-10 16:37:32 +00:00
|
|
|
children: [
|
|
|
|
MapButton(
|
|
|
|
icon: Icons.add,
|
|
|
|
onPressed: () {
|
|
|
|
_mapController.move(
|
|
|
|
_mapController.center,
|
|
|
|
_mapController.zoom + 1,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
heroTag: 'zoom-in',
|
|
|
|
),
|
2023-12-15 16:20:13 +00:00
|
|
|
const SizedBox(height: 8),
|
2023-12-10 16:37:32 +00:00
|
|
|
MapButton(
|
|
|
|
icon: Icons.remove,
|
|
|
|
onPressed: () {
|
|
|
|
_mapController.move(
|
|
|
|
_mapController.center,
|
|
|
|
_mapController.zoom - 1,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
heroTag: 'zoom-out',
|
|
|
|
),
|
2023-12-15 16:20:13 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
MapButton(
|
|
|
|
icon: Icons.check,
|
|
|
|
onPressed: () async {
|
|
|
|
if (selectedLocation.value == null) {
|
|
|
|
unawaited(
|
|
|
|
showShortToast(
|
|
|
|
context,
|
|
|
|
"Select a location first",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await FilesService.instance.bulkEditLocationData(
|
|
|
|
widget.files,
|
|
|
|
selectedLocation.value,
|
|
|
|
context,
|
|
|
|
);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
heroTag: 'add-location',
|
|
|
|
),
|
2023-12-10 16:37:32 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-12-10 17:36:07 +00:00
|
|
|
ValueListenableBuilder(
|
2023-12-11 08:11:57 +00:00
|
|
|
valueListenable: hasSelectedLocation,
|
2023-12-10 17:36:07 +00:00
|
|
|
builder: (context, value, _) {
|
2023-12-11 08:11:57 +00:00
|
|
|
return value
|
2023-12-15 17:05:13 +00:00
|
|
|
? Positioned(
|
|
|
|
bottom: 32,
|
2023-12-10 17:36:07 +00:00
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
2023-12-15 17:05:13 +00:00
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable: isDragging,
|
|
|
|
builder: (context, value, child) {
|
|
|
|
return AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
height: value ? 32 : 16,
|
|
|
|
// color: Colors.yellow,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: const Icon(
|
|
|
|
Icons.location_on,
|
|
|
|
color: Color.fromARGB(255, 250, 34, 19),
|
|
|
|
size: 32,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Transform(
|
|
|
|
transform: Matrix4.translationValues(0, 21, 0),
|
|
|
|
child: Container(
|
|
|
|
height: 2,
|
|
|
|
width: 12,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
boxShadow: shadowMenuDark,
|
|
|
|
// borderRadius: BorderRadius.circular(2),
|
|
|
|
// color: Colors.yellow,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-12-10 17:36:07 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink();
|
|
|
|
},
|
|
|
|
),
|
2023-12-10 16:37:32 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|