feat(map in info): go to full map on tapping map in file info

This commit is contained in:
ashilkn 2024-01-29 21:03:46 +05:30
parent c13e07b5cf
commit 6d6f4bb36a
3 changed files with 40 additions and 10 deletions

View file

@ -22,10 +22,14 @@ class MapScreen extends StatefulWidget {
// Add a function parameter where the function returns a Future<List<File>>
final Future<List<EnteFile>> Function() filesFutureFn;
final LatLng? center;
final double initialZoom;
const MapScreen({
super.key,
required this.filesFutureFn,
this.center,
this.initialZoom = 4.5,
});
@override
@ -41,7 +45,6 @@ class _MapScreenState extends State<MapScreen> {
StreamController<List<EnteFile>>.broadcast();
MapController mapController = MapController();
bool isLoading = true;
double initialZoom = 4.5;
double maxZoom = 18.0;
double minZoom = 2.8;
int debounceDuration = 500;
@ -109,13 +112,16 @@ class _MapScreenState extends State<MapScreen> {
}
if (hasAnyLocation) {
center = LatLng(
mostRecentFile!.location!.latitude!,
mostRecentFile.location!.longitude!,
);
center = widget.center ??
LatLng(
mostRecentFile!.location!.latitude!,
mostRecentFile.location!.longitude!,
);
if (kDebugMode) {
debugPrint("Info for map: center $center, initialZoom $initialZoom");
debugPrint(
"Info for map: center $center, initialZoom ${widget.initialZoom}",
);
}
} else {
showShortToast(context, S.of(context).noImagesWithLocation);
@ -127,7 +133,7 @@ class _MapScreenState extends State<MapScreen> {
mapController.move(
center,
initialZoom,
widget.initialZoom,
);
Timer(Duration(milliseconds: debounceDuration), () {
@ -211,7 +217,7 @@ class _MapScreenState extends State<MapScreen> {
imageMarkers: imageMarkers,
updateVisibleImages: calculateVisibleMarkers,
center: center,
initialZoom: initialZoom,
initialZoom: widget.initialZoom,
minZoom: minZoom,
maxZoom: maxZoom,
debounceDuration: debounceDuration,

View file

@ -22,6 +22,7 @@ class MapView extends StatefulWidget {
final double bottomSheetDraggableAreaHeight;
final bool showControls;
final int interactiveFlags;
final VoidCallback? onTap;
const MapView({
Key? key,
@ -34,6 +35,7 @@ class MapView extends StatefulWidget {
required this.initialZoom,
required this.debounceDuration,
required this.bottomSheetDraggableAreaHeight,
this.onTap,
this.interactiveFlags = InteractiveFlag.all,
this.showControls = true,
}) : super(key: key);
@ -75,6 +77,11 @@ class _MapViewState extends State<MapView> {
FlutterMap(
mapController: widget.controller,
options: MapOptions(
onTap: widget.onTap != null
? (_, __) {
widget.onTap!.call();
}
: null,
center: widget.center,
minZoom: widget.minZoom,
maxZoom: widget.maxZoom,

View file

@ -8,11 +8,13 @@ import "package:photos/events/location_tag_updated_event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/file/file.dart";
import "package:photos/services/location_service.dart";
import "package:photos/services/search_service.dart";
import "package:photos/states/location_screen_state.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/buttons/chip_button_widget.dart";
import "package:photos/ui/components/info_item_widget.dart";
import "package:photos/ui/map/image_marker.dart";
import "package:photos/ui/map/map_screen.dart";
import "package:photos/ui/map/map_view.dart";
import 'package:photos/ui/viewer/location/add_location_sheet.dart';
import "package:photos/ui/viewer/location/location_screen.dart";
@ -27,6 +29,7 @@ class LocationTagsWidget extends StatefulWidget {
}
class _LocationTagsWidgetState extends State<LocationTagsWidget> {
static const mapZoom = 7.0;
String? title;
IconData? leadingIcon;
bool? hasChipButtons;
@ -87,13 +90,27 @@ class _LocationTagsWidgetState extends State<LocationTagsWidget> {
widget.file.location!.latitude!,
widget.file.location!.longitude!,
),
minZoom: 7,
maxZoom: 7,
minZoom: mapZoom,
maxZoom: mapZoom,
initialZoom: 7,
debounceDuration: 0,
bottomSheetDraggableAreaHeight: 0,
showControls: false,
interactiveFlags: InteractiveFlag.none,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MapScreen(
filesFutureFn: SearchService.instance.getAllFiles,
center: LatLng(
widget.file.location!.latitude!,
widget.file.location!.longitude!,
),
initialZoom: mapZoom + 1,
),
),
);
},
),
),