From 12f6f59a1c2e1aa44aa003146cdc8b72072d9280 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Thu, 31 Oct 2024 00:19:40 +0800 Subject: [PATCH] Extract function to launch map app --- app/lib/gps_map_util.dart | 13 +++++++++++++ app/lib/widget/viewer_detail_pane.dart | 17 +++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/lib/gps_map_util.dart b/app/lib/gps_map_util.dart index 467679f2..3121343d 100644 --- a/app/lib/gps_map_util.dart +++ b/app/lib/gps_map_util.dart @@ -1,4 +1,6 @@ +import 'package:android_intent_plus/android_intent.dart'; import 'package:np_gps_map/np_gps_map.dart'; +import 'package:np_platform_util/np_platform_util.dart'; extension GpsMapProviderExtension on GpsMapProvider { String toUserString() { @@ -10,3 +12,14 @@ extension GpsMapProviderExtension on GpsMapProvider { } } } + +void launchExternalMap(CameraPosition location) { + if (getRawPlatform() == NpPlatform.android) { + final intent = AndroidIntent( + action: "action_view", + data: Uri.encodeFull( + "geo:${location.center.latitude},${location.center.longitude}?z=${location.zoom}"), + ); + intent.launch(); + } +} diff --git a/app/lib/widget/viewer_detail_pane.dart b/app/lib/widget/viewer_detail_pane.dart index 2d93cddf..1aa4e5b1 100644 --- a/app/lib/widget/viewer_detail_pane.dart +++ b/app/lib/widget/viewer_detail_pane.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:android_intent_plus/android_intent.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:intl/intl.dart'; @@ -19,6 +18,7 @@ import 'package:nc_photos/entity/exif_extension.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; +import 'package:nc_photos/gps_map_util.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/platform/features.dart' as features; @@ -358,7 +358,10 @@ class _ViewerDetailPaneState extends State { builder: (context, gpsMapProvider) => StaticMap( providerHint: gpsMapProvider.requireData, location: CameraPosition(center: _gps!, zoom: 16), - onTap: _onMapTap, + onTap: () => launchExternalMap(CameraPosition( + center: _gps!, + zoom: 16, + )), ), ), ), @@ -492,16 +495,6 @@ class _ViewerDetailPaneState extends State { SetAsHandler(c, context: context).setAsFile(widget.account, _file!); } - void _onMapTap() { - if (getRawPlatform() == NpPlatform.android) { - final intent = AndroidIntent( - action: "action_view", - data: Uri.encodeFull("geo:${_gps!.latitude},${_gps!.longitude}?z=16"), - ); - intent.launch(); - } - } - void _onDateTimeTap(BuildContext context) { assert(_file != null); showDialog(