add share location to InputBar popup.

This commit is contained in:
ericz committed 2026-10-08 21:33:42 +02:00
1 parent a64a33d0c0
commit 6cb8e07173
25 files changed
+511 -36

No files matched your search

+121 -2
View File
@@ -38,6 +38,7 @@ import '../widgets/received_image_message.dart';
import '../widgets/byte_count_input.dart';
import '../widgets/chat_day_separator.dart';
import '../widgets/empty_state.dart';
import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/emoji_picker.dart';
import '../widgets/gif_message.dart';
@@ -2011,6 +2012,79 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
}
Widget _buildInputBar() {
Future<String?> promptForMarkerLabel(
BuildContext context, {
required double lat,
required double lon,
required String defaultLabel,
required String flags,
}) async {
final controller = TextEditingController(text: defaultLabel);
controller.selection = TextSelection(
baseOffset: 0,
extentOffset: controller.text.length,
);
final focusNode = FocusNode();
final latStr = lat.toStringAsFixed(6);
final lonStr = lon.toStringAsFixed(6);
final prefix = 'm:$latStr,$lonStr|';
final suffix = '|$flags';
final overheadBytes = utf8.encode(prefix + suffix).length;
final maxForContact = maxContactMessageBytes();
final maxForChannel = maxChannelMessageBytes(null);
final maxPayload = maxForContact < maxForChannel
? maxForContact
: maxForChannel;
final allowedLabelBytes = (maxPayload - overheadBytes) > 0
? (maxPayload - overheadBytes)
: 0;
try {
final result = await showDialog<String>(
context: context,
builder: (dialogContext) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (dialogContext.mounted) {
focusNode.requestFocus();
controller.selection = TextSelection(
baseOffset: 0,
extentOffset: controller.text.length,
);
}
});
return AlertDialog(
title: Text(dialogContext.l10n.map_pinLabel),
content: ByteCountedTextField(
focusNode: focusNode,
maxBytes: allowedLabelBytes,
controller: controller,
decoration: InputDecoration(
helperText: dialogContext.l10n.map_labelUpdateHint,
helperMaxLines: 3,
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext, null),
child: Text(dialogContext.l10n.common_cancel),
),
FilledButton(
onPressed: () =>
Navigator.pop(dialogContext, controller.text.trim()),
child: Text(dialogContext.l10n.common_share),
),
],
);
},
);
return result;
} finally {
focusNode.dispose();
controller.dispose();
}
}
final connector = context.watch<MeshCoreConnector>();
final maxBytes = maxChannelMessageBytes(connector.selfName);
final settings = context.watch<AppSettingsService>().settings;
@@ -2044,9 +2118,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
PopupMenuButton<String>(
icon: const Icon(Icons.add_circle_outline),
position: PopupMenuPosition.over,
offset: Offset(0, showImageAction ? -112 : -64),
offset: Offset(0, showImageAction ? -220 : -160),
tooltip: context.l10n.chat_selectSendAction,
onSelected: (action) {
onSelected: (action) async {
switch (action) {
case 'gif':
_showGifPicker(context);
@@ -2054,6 +2128,39 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
case 'meshcore-image':
_showImageSendPreview();
break;
case 'send-my-location':
final connector = context.read<MeshCoreConnector>();
if (connector.selfLatitude == null ||
connector.selfLongitude == null) {
showDismissibleSnackBar(
context,
content: Text(
context.l10n.map_connectToShareMarkers,
),
);
break;
}
final lat = connector.selfLatitude!;
final lon = connector.selfLongitude!;
final initialLabel =
connector.selfName?.isNotEmpty == true
? connector.selfName!
: context.l10n.map_sharedPin;
final label = await promptForMarkerLabel(
context,
lat: lat,
lon: lon,
defaultLabel: initialLabel,
flags: 'poi',
);
if (label == null || label.trim().isEmpty) break;
final markerText =
'm:${lat.toStringAsFixed(6)},${lon.toStringAsFixed(6)}|${label.trim()}|poi';
connector.sendChannelMessage(
widget.channel,
markerText,
);
break;
}
},
itemBuilder: (context) => [
@@ -2078,6 +2185,18 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
],
),
),
if (connector.selfLatitude != null &&
connector.selfLongitude != null)
PopupMenuItem(
value: 'send-my-location',
child: Row(
children: [
const Icon(Icons.my_location),
const SizedBox(width: 12),
Text(context.l10n.map_shareMarkerHere),
],
),
),
],
),
if (settings.translationEnabled)