Files
maps_bookmarks/lib/service/maps_launcher_service.dart
2026-01-22 18:20:08 +01:00

53 lines
1.2 KiB
Dart

import 'dart:io' show Platform;
import 'package:android_intent_plus/android_intent.dart';
class MapsLauncherService {
static Future<bool> openInGoogleMaps(String url) async {
if (!Platform.isAndroid) return false;
try {
// Try to open in Google Maps app
final intent = AndroidIntent(
action: 'action_view',
data: url,
package: 'com.google.android.apps.maps',
);
await intent.launch();
return true;
} catch (e) {
// Google Maps not installed, try browser as fallback
try {
final browserIntent = AndroidIntent(action: 'action_view', data: url);
await browserIntent.launch();
return true;
} catch (e) {
return false;
}
}
}
static Future<bool> shareLocation({
required String text,
String? subject,
}) async {
if (!Platform.isAndroid) return false;
try {
final intent = AndroidIntent(
action: 'action_send',
type: 'text/plain',
arguments: {
'android.intent.extra.TEXT': text,
if (subject != null) 'android.intent.extra.SUBJECT': subject,
},
);
await intent.launch();
return true;
} catch (e) {
return false;
}
}
}