Extract function to launch map app

This commit is contained in:
Ming Ming 2024-10-31 00:19:40 +08:00
parent 3a1f6d64cf
commit 12f6f59a1c
2 changed files with 18 additions and 12 deletions

View file

@ -1,4 +1,6 @@
import 'package:android_intent_plus/android_intent.dart';
import 'package:np_gps_map/np_gps_map.dart'; import 'package:np_gps_map/np_gps_map.dart';
import 'package:np_platform_util/np_platform_util.dart';
extension GpsMapProviderExtension on GpsMapProvider { extension GpsMapProviderExtension on GpsMapProvider {
String toUserString() { 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();
}
}

View file

@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.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.dart';
import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util; 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/k.dart' as k;
import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/platform/features.dart' as features; import 'package:nc_photos/platform/features.dart' as features;
@ -358,7 +358,10 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
builder: (context, gpsMapProvider) => StaticMap( builder: (context, gpsMapProvider) => StaticMap(
providerHint: gpsMapProvider.requireData, providerHint: gpsMapProvider.requireData,
location: CameraPosition(center: _gps!, zoom: 16), location: CameraPosition(center: _gps!, zoom: 16),
onTap: _onMapTap, onTap: () => launchExternalMap(CameraPosition(
center: _gps!,
zoom: 16,
)),
), ),
), ),
), ),
@ -492,16 +495,6 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
SetAsHandler(c, context: context).setAsFile(widget.account, _file!); 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) { void _onDateTimeTap(BuildContext context) {
assert(_file != null); assert(_file != null);
showDialog( showDialog(