Skip to content

Commit

Permalink
Display geo link in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
Xennis committed Sep 28, 2023
1 parent 7d6835e commit 3df6c3c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 3 additions & 1 deletion green_walking/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
"mapSwitchLayerSemanticLabel": "Kartenansicht wechseln",
"rateApp": "Bewerte die App",
"geocodingResultLegalNotice": "Suchergebnisse: {legalNotice}",
"geocodingAdvancedSearchButton": "Erweiterte search"
"geocodingAdvancedSearchButton": "Erweiterte Suche",
"openLocationInDefaultAppSemanticLabel": "Öffnen mit Standardapp",
"openLocationDetailsSemanticLabel": "Details anzeigen"
}
8 changes: 8 additions & 0 deletions green_walking/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,13 @@
"geocodingAdvancedSearchButton": "Advanced search",
"@geocodingAdvancedSearchButton": {
"description": "Label for the button to enable/execute the advanced search."
},
"openLocationInDefaultAppSemanticLabel": "Open with default app",
"@openLocationInDefaultAppSemanticLabel": {
"description": "Semantic label to open a location with the phones default app."
},
"openLocationDetailsSemanticLabel": "Show details",
"@openLocationDetailsSemanticLabel": {
"description": "Semantic label to open details of a location."
}
}
32 changes: 21 additions & 11 deletions green_walking/lib/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart' show Position;
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';

import '../core.dart';
import '../services/geocoding.dart';
Expand Down Expand Up @@ -131,9 +132,6 @@ class _SearchPageState extends State<SearchPage> {
truncateString(elem.placeName?.replaceFirst('${elem.text ?? ''}, ', ''), 65) ?? '';
return Card(
child: ListTile(
leading: CircleAvatar(
child: Text((index + 1).toString()),
),
isThreeLine: true,
onTap: () {
Navigator.pop(
Expand All @@ -143,7 +141,7 @@ class _SearchPageState extends State<SearchPage> {
},
title: Text(truncateString(elem.text, 25) ?? ''),
subtitle: Text(subtitle),
trailing: _trailingWidget(locale, elem.url),
trailing: _trailingWidget(locale, elem),
),
);
},
Expand All @@ -167,14 +165,26 @@ class _SearchPageState extends State<SearchPage> {
});
}

Widget? _trailingWidget(AppLocalizations locale, Uri? url) {
if (url == null) {
return null;
Widget? _trailingWidget(AppLocalizations locale, GeocodingPlace place) {
final List<Widget> children = [
IconButton(
color: Theme.of(context).colorScheme.secondary,
tooltip: locale.openLocationInDefaultAppSemanticLabel,
icon: Icon(Icons.open_in_new, semanticLabel: locale.openLocationInDefaultAppSemanticLabel),
onPressed: () => launchUrlString(
'geo:${place.center!.lat.toStringAsFixed(6)},${place.center!.lng.toStringAsFixed(6)}?q=${Uri.encodeComponent(place.placeName!)}'))
];
final Uri? url = place.url;
if (url != null) {
children.insert(
0,
IconButton(
color: Theme.of(context).primaryColor,
tooltip: locale.openLocationDetailsSemanticLabel,
icon: Icon(Icons.info_outline, semanticLabel: locale.openLocationDetailsSemanticLabel),
onPressed: () => launchUrl(url)));
}
return IconButton(
splashColor: Colors.grey,
icon: Icon(Icons.open_in_new, semanticLabel: locale.openInBrowserSemanticLabel),
onPressed: () => launchUrl(url));
return Wrap(spacing: 1.0, children: children);
}

Widget _advancedSearchButton(AppLocalizations locale, bool enable) {
Expand Down

0 comments on commit 3df6c3c

Please sign in to comment.