Add interactive GPS coordinates in messages

This commit is contained in:
zjs81 committed 2026-11-21 17:43:15 -07:00
1 parent 2f8fcb87d7
commit 05b47a037b
33 files changed
+1985 -84

No files matched your search

+277
View File
@@ -0,0 +1,277 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import '../utils/platform_info.dart';
/// A parsed WGS84 decimal coordinate pair (`latitude, longitude`) found in text.
@immutable
class ParsedCoordinate {
final double latitude;
final double longitude;
final String rawText;
final int start;
final int end;
const ParsedCoordinate({
required this.latitude,
required this.longitude,
required this.rawText,
required this.start,
required this.end,
});
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ParsedCoordinate &&
latitude == other.latitude &&
longitude == other.longitude &&
rawText == other.rawText &&
start == other.start &&
end == other.end;
@override
int get hashCode => Object.hash(latitude, longitude, rawText, start, end);
@override
String toString() =>
'ParsedCoordinate($latitude, $longitude, "$rawText", $start..$end)';
}
/// Linkify element representing a detected GPS coordinate pair.
class CoordinateElement extends LinkableElement {
final double latitude;
final double longitude;
CoordinateElement({
required this.latitude,
required this.longitude,
required String rawText,
}) : super(
rawText,
buildExternalMapUri(latitude, longitude).toString(),
rawText,
);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CoordinateElement &&
super.equals(other) &&
latitude == other.latitude &&
longitude == other.longitude;
@override
int get hashCode => Object.hash(super.hashCode, latitude, longitude);
@override
String toString() => "CoordinateElement: '$text' ($latitude, $longitude)";
}
/// Builds a platform-appropriate external maps URI for [latitude] and [longitude].
Uri buildExternalMapUri(
double latitude,
double longitude, {
TargetPlatform? platform,
bool? isWeb,
}) {
final normalizedLat = latitude == 0 ? 0.0 : latitude;
final normalizedLon = longitude == 0 ? 0.0 : longitude;
final latStr = normalizedLat.toString();
final lonStr = normalizedLon.toString();
final web = isWeb ?? PlatformInfo.isWeb;
if (web) {
return Uri.parse(
'https://www.openstreetmap.org/?mlat=$latStr&mlon=$lonStr#map=16/$latStr/$lonStr',
);
}
final targetPlatform = platform ?? defaultTargetPlatform;
return switch (targetPlatform) {
TargetPlatform.android => Uri.parse(
'geo:$latStr,$lonStr?q=$latStr,$lonStr',
),
TargetPlatform.iOS || TargetPlatform.macOS => Uri.parse(
'https://maps.apple.com/?ll=$latStr,$lonStr&q=$latStr,$lonStr',
),
TargetPlatform.linux ||
TargetPlatform.windows ||
TargetPlatform.fuchsia => Uri.parse(
'https://www.openstreetmap.org/?mlat=$latStr&mlon=$lonStr#map=16/$latStr/$lonStr',
),
};
}
/// Detects decimal `latitude, longitude` GPS coordinates inside [TextElement]s
/// while avoiding URLs, version numbers, integer pairs, and embedded identifiers.
class CoordinateLinkifier extends Linkifier {
const CoordinateLinkifier();
static final RegExp _candidateRegex = RegExp(
r'([+-]?\d+\.\d+),[ \t]*([+-]?\d+\.\d+)',
);
// Covers URI schemes and bare domain/path strings that UrlLinkifier leaves
// as plain text (e.g. geo:..., ftp://..., maps.google.com/?q=...).
static final RegExp _nonLinkifiedUrlRegex = RegExp(
r'(?:[a-zA-Z][a-zA-Z0-9+.-]*://|geo:|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/)[^\s]*',
);
static final RegExp _disallowedBoundaryChar = RegExp(r'[A-Za-z0-9_+-]');
static final RegExp _asciiDigit = RegExp(r'[0-9]');
@override
List<LinkifyElement> parse(
List<LinkifyElement> elements,
LinkifyOptions options,
) {
final result = <LinkifyElement>[];
for (final element in elements) {
if (element is! TextElement) {
result.add(element);
continue;
}
result.addAll(_parseSegment(element.text));
}
return result;
}
static List<LinkifyElement> _parseSegment(String text) {
final blockedRanges = <({int start, int end})>[
for (final m in _nonLinkifiedUrlRegex.allMatches(text))
(start: m.start, end: m.end),
];
final elements = <LinkifyElement>[];
var cursor = 0;
for (final match in _candidateRegex.allMatches(text)) {
if (_isInsideRanges(match.start, match.end, blockedRanges)) {
continue;
}
if (!_hasValidBoundaries(text, match.start, match.end)) {
continue;
}
final lat = double.tryParse(match.group(1)!);
final lon = double.tryParse(match.group(2)!);
if (lat == null || lon == null || !lat.isFinite || !lon.isFinite) {
continue;
}
if (lat < -90.0 || lat > 90.0 || lon < -180.0 || lon > 180.0) {
continue;
}
if (match.start > cursor) {
elements.add(TextElement(text.substring(cursor, match.start)));
}
elements.add(
CoordinateElement(
latitude: lat == 0 ? 0.0 : lat,
longitude: lon == 0 ? 0.0 : lon,
rawText: match.group(0)!,
),
);
cursor = match.end;
}
if (elements.isEmpty) {
return [TextElement(text)];
}
if (cursor < text.length) {
elements.add(TextElement(text.substring(cursor)));
}
return elements;
}
static bool _isInsideRanges(
int start,
int end,
List<({int start, int end})> ranges,
) {
for (final range in ranges) {
if (start < range.end && end > range.start) {
return true;
}
}
return false;
}
static bool _hasValidBoundaries(String text, int start, int end) {
if (start > 0) {
final prev = text[start - 1];
if (prev == '.' || _disallowedBoundaryChar.hasMatch(prev)) {
return false;
}
}
if (end < text.length) {
final next = text[end];
if (_disallowedBoundaryChar.hasMatch(next)) {
return false;
}
// Reject version-like continuations (e.g. "1.2,3.4.5"), while allowing
// trailing sentence periods (e.g. "38.722,-9.139.").
if (next == '.' &&
end + 1 < text.length &&
_asciiDigit.hasMatch(text[end + 1])) {
return false;
}
}
return true;
}
}
/// Shared parser returning linkified elements and extracted [ParsedCoordinate]s.
class CoordinateParser {
CoordinateParser._();
static const LinkifyOptions linkifyOptions = LinkifyOptions(
humanize: false,
defaultToHttps: false,
);
static const List<Linkifier> linkifiers = [
UrlLinkifier(),
EmailLinkifier(),
CoordinateLinkifier(),
];
/// Splits [text] into URL, email, coordinate, and plain-text elements.
static List<LinkifyElement> linkifyWithCoordinates(String text) {
if (text.isEmpty) return const [];
var elements = <LinkifyElement>[TextElement(text)];
for (final linkifier in linkifiers) {
elements = linkifier.parse(elements, linkifyOptions);
}
return elements;
}
/// Extracts all valid WGS84 decimal coordinates in [text].
static List<ParsedCoordinate> parse(String text) {
if (text.isEmpty) return const [];
final elements = linkifyWithCoordinates(text);
final results = <ParsedCoordinate>[];
var offset = 0;
for (final element in elements) {
final raw = element.originText;
final index = text.indexOf(raw, offset);
final start = index >= 0 ? index : offset;
final end = start + raw.length;
if (element is CoordinateElement) {
results.add(
ParsedCoordinate(
latitude: element.latitude,
longitude: element.longitude,
rawText: element.text,
start: start,
end: end,
),
);
}
offset = end;
}
return results;
}
}
+311 -45
View File
@@ -1,10 +1,16 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';
import '../l10n/l10n.dart';
import '../utils/platform_info.dart';
import '../helpers/coordinate_parser.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../screens/coordinate_map_screen.dart';
import '../theme/mesh_theme.dart';
import '../utils/platform_info.dart';
import '../widgets/mesh_ui.dart';
class LinkHandler {
static TextStyle defaultLinkStyle(BuildContext context, TextStyle base) {
@@ -15,60 +21,153 @@ class LinkHandler {
return base.copyWith(color: orange, decoration: TextDecoration.underline);
}
/// The system text scale as a linear factor for [style]'s size.
///
/// flutter_linkify only takes a `textScaleFactor` (default 1.0, which
/// ignores the system font size), so the ambient [TextScaler] is sampled
/// at the style's font size to keep Android's nonlinear scaling. The
/// in-app chat text scale is already part of `style.fontSize`.
static double systemTextScaleFactor(BuildContext context, TextStyle style) {
final fontSize =
style.fontSize ?? DefaultTextStyle.of(context).style.fontSize ?? 14;
if (fontSize <= 0) return 1.0;
return MediaQuery.textScalerOf(context).scale(fontSize) / fontSize;
static Color _inferBackground(BuildContext context, TextStyle base) {
final textColor = base.color;
if (textColor != null) {
return textColor.computeLuminance() > 0.5
? MeshPalette.bg2
: Colors.white;
}
return Theme.of(context).colorScheme.surfaceContainerLow;
}
/// Returns a [SelectableLinkify] on desktop or a [Linkify] on mobile.
static TextStyle defaultCoordinateStyle(
BuildContext context,
TextStyle base, {
Color? backgroundColor,
}) {
final scheme = Theme.of(context).colorScheme;
final effectiveBg = backgroundColor ?? _inferBackground(context, base);
final accent = readableAccent(
scheme.primary,
effectiveBg,
minContrast: 4.5,
);
return base.copyWith(
color: accent,
decoration: TextDecoration.underline,
decorationColor: accent,
fontWeight: FontWeight.w600,
);
}
/// Returns an interactive rich-text widget (selectable on desktop) with URL,
/// email, and GPS coordinate detection.
static Widget buildLinkifyText({
required BuildContext context,
required String text,
required TextStyle style,
TextStyle? linkStyle,
TextStyle? coordinateStyle,
Color? backgroundColor,
VoidCallback? onSecondaryTap,
}) {
final effectiveLinkStyle = linkStyle ?? defaultLinkStyle(context, style);
const options = LinkifyOptions(humanize: false, defaultToHttps: false);
const linkifiers = [UrlLinkifier(), EmailLinkifier()];
void onOpen(LinkableElement link) => handleLinkTap(context, link.url);
final textScaleFactor = systemTextScaleFactor(context, style);
if (PlatformInfo.isDesktop) {
final linkify = SelectableLinkify(
text: text,
style: style,
linkStyle: effectiveLinkStyle,
options: options,
linkifiers: linkifiers,
onOpen: onOpen,
textScaleFactor: textScaleFactor,
);
if (onSecondaryTap == null) return linkify;
return Listener(
onPointerDown: (event) {
if (event.buttons & kSecondaryMouseButton != 0) onSecondaryTap();
},
behavior: HitTestBehavior.translucent,
child: linkify,
);
}
return Linkify(
return _InteractiveMessageText(
text: text,
style: style,
linkStyle: effectiveLinkStyle,
options: options,
linkifiers: linkifiers,
onOpen: onOpen,
textScaleFactor: textScaleFactor,
linkStyle: linkStyle,
coordinateStyle: coordinateStyle,
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
);
}
static void openCoordinateMap(
BuildContext context,
CoordinateElement coordinate,
) {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => CoordinateMapScreen(
latitude: coordinate.latitude,
longitude: coordinate.longitude,
label: coordinate.text,
),
),
);
}
static Future<void> copyCoordinateLocation(
BuildContext context,
String text,
) async {
await Clipboard.setData(ClipboardData(text: text));
if (!context.mounted) return;
showDismissibleSnackBar(
context,
content: Text(context.l10n.coordinate_copied),
);
}
static Future<void> openCoordinateInExternalMaps(
BuildContext context,
double latitude,
double longitude,
) async {
final uri = buildExternalMapUri(latitude, longitude);
try {
if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
if (context.mounted) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_couldNotOpenLink(uri.toString())),
backgroundColor: Theme.of(context).colorScheme.error,
);
}
}
} catch (_) {
if (context.mounted) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chat_couldNotOpenLink(uri.toString())),
backgroundColor: Theme.of(context).colorScheme.error,
);
}
}
}
static Future<void> showCoordinateActionSheet(
BuildContext context,
CoordinateElement coordinate,
) {
return showMeshSheet<void>(
context,
builder: (sheetContext) {
final l10n = sheetContext.l10n;
return SafeArea(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BottomSheetHeader(
title: coordinate.text,
subtitle: l10n.chat_location,
),
ListTile(
leading: const Icon(Icons.copy),
title: Text(l10n.coordinate_copyLocation),
onTap: () {
Navigator.pop(sheetContext);
copyCoordinateLocation(context, coordinate.text);
},
),
ListTile(
leading: const Icon(Icons.open_in_new),
title: Text(l10n.coordinate_openInMaps),
onTap: () {
Navigator.pop(sheetContext);
openCoordinateInExternalMaps(
context,
coordinate.latitude,
coordinate.longitude,
);
},
),
],
),
),
);
},
);
}
@@ -139,3 +238,170 @@ class LinkHandler {
}
}
}
/// Extends [TapGestureRecognizer] so Flutter's paragraph/editable semantics
/// recognize it as a tappable link while also forwarding pointers to an owned
/// [LongPressGestureRecognizer] in the same gesture arena.
class _CoordinateGestureRecognizer extends TapGestureRecognizer {
final LongPressGestureRecognizer _longPress;
_CoordinateGestureRecognizer({
required VoidCallback onTap,
required VoidCallback onLongPress,
}) : _longPress = LongPressGestureRecognizer()..onLongPress = onLongPress {
this.onTap = onTap;
}
@override
void addPointer(PointerDownEvent event) {
super.addPointer(event);
_longPress.addPointer(event);
}
@override
void dispose() {
_longPress.dispose();
super.dispose();
}
}
class _InteractiveMessageText extends StatefulWidget {
final String text;
final TextStyle style;
final TextStyle? linkStyle;
final TextStyle? coordinateStyle;
final Color? backgroundColor;
final VoidCallback? onSecondaryTap;
const _InteractiveMessageText({
required this.text,
required this.style,
this.linkStyle,
this.coordinateStyle,
this.backgroundColor,
this.onSecondaryTap,
});
@override
State<_InteractiveMessageText> createState() =>
_InteractiveMessageTextState();
}
class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
late List<LinkifyElement> _elements;
final List<GestureRecognizer> _recognizers = [];
@override
void initState() {
super.initState();
_rebuildSpans();
}
@override
void didUpdateWidget(covariant _InteractiveMessageText oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.text != widget.text) {
_disposeRecognizers();
_rebuildSpans();
}
}
@override
void dispose() {
_disposeRecognizers();
super.dispose();
}
void _disposeRecognizers() {
for (final recognizer in _recognizers) {
recognizer.dispose();
}
_recognizers.clear();
}
void _rebuildSpans() {
_elements = CoordinateParser.linkifyWithCoordinates(widget.text);
}
InlineSpan _buildElementSpan(
LinkifyElement element,
TextStyle effectiveLinkStyle,
TextStyle effectiveCoordinateStyle,
) {
if (element is CoordinateElement) {
final recognizer = _CoordinateGestureRecognizer(
onTap: () {
if (!mounted) return;
LinkHandler.openCoordinateMap(context, element);
},
onLongPress: () {
if (!mounted) return;
LinkHandler.showCoordinateActionSheet(context, element);
},
);
_recognizers.add(recognizer);
return TextSpan(
text: element.text,
style: effectiveCoordinateStyle,
recognizer: recognizer,
mouseCursor: SystemMouseCursors.click,
);
}
if (element is LinkableElement) {
final recognizer = TapGestureRecognizer()
..onTap = () {
if (!mounted) return;
LinkHandler.handleLinkTap(context, element.url);
};
_recognizers.add(recognizer);
return TextSpan(
text: element.text,
style: effectiveLinkStyle,
recognizer: recognizer,
mouseCursor: SystemMouseCursors.click,
);
}
return TextSpan(text: element.text, style: widget.style);
}
@override
Widget build(BuildContext context) {
_disposeRecognizers();
final effectiveLinkStyle =
widget.linkStyle ?? LinkHandler.defaultLinkStyle(context, widget.style);
final effectiveCoordinateStyle =
widget.coordinateStyle ??
LinkHandler.defaultCoordinateStyle(
context,
widget.style,
backgroundColor: widget.backgroundColor,
);
final span = TextSpan(
style: widget.style,
children: [
for (final element in _elements)
_buildElementSpan(
element,
effectiveLinkStyle,
effectiveCoordinateStyle,
),
],
);
if (PlatformInfo.isDesktop) {
final selectable = SelectableText.rich(span);
if (widget.onSecondaryTap == null) return selectable;
return Listener(
onPointerDown: (event) {
if (event.buttons & kSecondaryMouseButton != 0) {
widget.onSecondaryTap!();
}
},
behavior: HitTestBehavior.translucent,
child: selectable,
);
}
return Text.rich(span);
}
}
+5 -1
View File
@@ -4459,5 +4459,9 @@
"addContact_publicKeyInvalid": "Public key must be 64 hex characters (32 bytes)",
"addContact_clipboardKeyLoaded": "Public key filled in. Choose a contact type, enter a name, and tap save.",
"addContact_fromDiscovered": "Add from Discovered Contacts",
"addContact_saveFailed": "Failed to add contact."
"addContact_saveFailed": "Failed to add contact.",
"coordinateMap_title": "Location",
"coordinate_copyLocation": "Copy location",
"coordinate_openInMaps": "Open in maps",
"coordinate_copied": "Location copied"
}
+24
View File
@@ -12957,6 +12957,30 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Failed to add contact.'**
String get addContact_saveFailed;
/// No description provided for @coordinateMap_title.
///
/// In en, this message translates to:
/// **'Location'**
String get coordinateMap_title;
/// No description provided for @coordinate_copyLocation.
///
/// In en, this message translates to:
/// **'Copy location'**
String get coordinate_copyLocation;
/// No description provided for @coordinate_openInMaps.
///
/// In en, this message translates to:
/// **'Open in maps'**
String get coordinate_openInMaps;
/// No description provided for @coordinate_copied.
///
/// In en, this message translates to:
/// **'Location copied'**
String get coordinate_copied;
}
class _AppLocalizationsDelegate
+12
View File
@@ -7780,4 +7780,16 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7751,4 +7751,16 @@ class AppLocalizationsCs extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7794,4 +7794,16 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7665,4 +7665,16 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7772,4 +7772,16 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7800,4 +7800,16 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7763,4 +7763,16 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7783,4 +7783,16 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7425,4 +7425,16 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7437,4 +7437,16 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7739,4 +7739,16 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7817,4 +7817,16 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7761,6 +7761,18 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
/// The translations for Portuguese, as used in Portugal (`pt_PT`).
+12
View File
@@ -7797,4 +7797,16 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7762,4 +7762,16 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7756,4 +7756,16 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7716,4 +7716,16 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7809,4 +7809,16 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+12
View File
@@ -7267,4 +7267,16 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get addContact_saveFailed => 'Failed to add contact.';
@override
String get coordinateMap_title => 'Location';
@override
String get coordinate_copyLocation => 'Copy location';
@override
String get coordinate_openInMaps => 'Open in maps';
@override
String get coordinate_copied => 'Location copied';
}
+3
View File
@@ -96,6 +96,9 @@ class _BookmarksScreenState extends State<BookmarksScreen> {
: bookmark.text,
style: textStyle,
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
backgroundColor:
Theme.of(context).cardTheme.color ??
Theme.of(context).colorScheme.surfaceContainerLow,
);
return Card(
margin: const EdgeInsets.only(bottom: 10),
+2
View File
@@ -1204,6 +1204,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
fontStyle: FontStyle.italic,
color: textColor.withValues(alpha: 0.72),
),
backgroundColor: colors.background,
onSecondaryTap: PlatformInfo.isDesktop
? () => _showMessageActions(message)
: null,
@@ -1356,6 +1357,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
alpha: 0.72,
),
),
backgroundColor: colors.background,
onSecondaryTap: PlatformInfo.isDesktop
? () => _showMessageActions(message)
: null,
+2
View File
@@ -1686,6 +1686,7 @@ class _MessageBubble extends StatelessWidget {
color: textColor.withValues(alpha: 0.72),
fontSize: bodyFontSize * textScale,
),
backgroundColor: colors.background,
onSecondaryTap: PlatformInfo.isDesktop ? onLongPress : null,
),
),
@@ -1820,6 +1821,7 @@ class _MessageBubble extends StatelessWidget {
),
fontSize: bodyFontSize * textScale,
),
backgroundColor: colors.background,
onSecondaryTap: PlatformInfo.isDesktop
? onLongPress
: null,
+260
View File
@@ -0,0 +1,260 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:provider/provider.dart';
import '../helpers/link_handler.dart';
import '../l10n/l10n.dart';
import '../services/map_tile_cache_service.dart';
import '../theme/mesh_theme.dart';
import '../widgets/adaptive_app_bar_title.dart';
import '../widgets/mesh_ui.dart';
/// Dedicated full-screen map centered on a tapped GPS coordinate.
class CoordinateMapScreen extends StatefulWidget {
final double latitude;
final double longitude;
final String? label;
const CoordinateMapScreen({
super.key,
required this.latitude,
required this.longitude,
this.label,
});
@override
State<CoordinateMapScreen> createState() => _CoordinateMapScreenState();
}
class _CoordinateMapScreenState extends State<CoordinateMapScreen> {
static const double _initialZoom = 15.0;
static const double _minZoom = 2.0;
static const double _maxZoom = 18.0;
final MapController _mapController = MapController();
LatLng get _position => LatLng(widget.latitude, widget.longitude);
String get _coordinateText => widget.label?.trim().isNotEmpty == true
? widget.label!.trim()
: '${widget.latitude}, ${widget.longitude}';
@override
void dispose() {
_mapController.dispose();
super.dispose();
}
void _zoomBy(double delta) {
final camera = _mapController.camera;
final nextZoom = (camera.zoom + delta).clamp(_minZoom, _maxZoom).toDouble();
_mapController.move(camera.center, nextZoom);
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final scheme = Theme.of(context).colorScheme;
final mapTheme = MeshMapTheme.of(context);
final tileCache = context.read<MapTileCacheService>();
final isDesktop =
defaultTargetPlatform == TargetPlatform.linux ||
defaultTargetPlatform == TargetPlatform.windows ||
defaultTargetPlatform == TargetPlatform.macOS;
final labelSurface = scheme.surfaceContainerLow;
final iconAccent = readableAccent(
scheme.primary,
labelSurface,
minContrast: 3,
);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: AdaptiveAppBarTitle(l10n.coordinateMap_title),
actions: [
IconButton(
icon: const Icon(Icons.copy),
tooltip: l10n.coordinate_copyLocation,
onPressed: () =>
LinkHandler.copyCoordinateLocation(context, _coordinateText),
),
IconButton(
icon: const Icon(Icons.open_in_new),
tooltip: l10n.coordinate_openInMaps,
onPressed: () => LinkHandler.openCoordinateInExternalMaps(
context,
widget.latitude,
widget.longitude,
),
),
],
),
body: Stack(
children: [
FlutterMap(
mapController: _mapController,
options: MapOptions(
initialCenter: _position,
initialZoom: _initialZoom,
minZoom: _minZoom,
maxZoom: _maxZoom,
interactionOptions: InteractionOptions(
flags: ~InteractiveFlag.rotate,
scrollWheelVelocity: isDesktop ? 0.012 : 0.005,
cursorKeyboardRotationOptions:
CursorKeyboardRotationOptions.disabled(),
keyboardOptions: isDesktop
? const KeyboardOptions(
enableArrowKeysPanning: true,
enableWASDPanning: true,
enableRFZooming: true,
)
: const KeyboardOptions.disabled(),
),
),
children: [
tileCache.buildTileLayer(context),
MarkerLayer(
markers: [
Marker(
point: _position,
width: 48,
height: 48,
child: IgnorePointer(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: mapTheme.followsTheme
? mapTheme.accent
: MapPalette.batteryLow,
border: Border.all(
color: MapPalette.markerOutline,
width: 3,
),
boxShadow: const [
BoxShadow(
color: MapPalette.markerShadow,
blurRadius: 8,
offset: Offset(0, 3),
),
],
),
child: const Icon(
Icons.location_on,
color: MapPalette.markerOutline,
size: 26,
),
),
),
),
],
),
],
),
Positioned(
top: 12,
right: 12,
child: Column(
children: [
_CoordinateMapControlButton(
icon: Icons.add,
tooltip: l10n.map_zoomIn,
onPressed: () => _zoomBy(1),
),
const SizedBox(height: 8),
_CoordinateMapControlButton(
icon: Icons.remove,
tooltip: l10n.map_zoomOut,
onPressed: () => _zoomBy(-1),
),
const SizedBox(height: 8),
_CoordinateMapControlButton(
icon: Icons.my_location,
tooltip: l10n.map_centerMap,
onPressed: () => _mapController.move(_position, _initialZoom),
),
],
),
),
Positioned(
left: 16,
right: 16,
bottom: 16,
child: SafeArea(
top: false,
child: Material(
color: labelSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(MeshRadii.md),
side: BorderSide(color: scheme.outlineVariant),
),
elevation: 2,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 10,
),
child: Row(
children: [
Icon(
Icons.location_on_outlined,
color: iconAccent,
size: 22,
),
const SizedBox(width: 10),
Expanded(
child: Text(
_coordinateText,
style: MeshTheme.mono(
fontSize: 14,
fontWeight: FontWeight.w600,
color: scheme.onSurface,
),
),
),
],
),
),
),
),
),
],
),
);
}
}
class _CoordinateMapControlButton extends StatelessWidget {
final IconData icon;
final String tooltip;
final VoidCallback onPressed;
const _CoordinateMapControlButton({
required this.icon,
required this.tooltip,
required this.onPressed,
});
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Material(
color: scheme.surfaceContainerLow,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(MeshRadii.md),
side: BorderSide(color: scheme.outlineVariant),
),
clipBehavior: Clip.antiAlias,
child: IconButton(
icon: Icon(icon),
tooltip: tooltip,
onPressed: onPressed,
iconSize: 22,
),
);
}
}
@@ -7,6 +7,7 @@ class TranslatedMessageContent extends StatelessWidget {
final String? originalText;
final TextStyle style;
final TextStyle? originalStyle;
final Color? backgroundColor;
final bool showOriginalFirst;
final VoidCallback? onSecondaryTap;
@@ -16,6 +17,7 @@ class TranslatedMessageContent extends StatelessWidget {
required this.style,
this.originalText,
this.originalStyle,
this.backgroundColor,
this.showOriginalFirst = true,
this.onSecondaryTap,
});
@@ -38,6 +40,7 @@ class TranslatedMessageContent extends StatelessWidget {
fontStyle: FontStyle.italic,
fontSize: style.fontSize,
),
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
)
: null;
@@ -45,6 +48,7 @@ class TranslatedMessageContent extends StatelessWidget {
context: context,
text: trimmedDisplay,
style: style,
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
);