From 4e1432ff9d8efabf45b6519b8c0fb8d8afc86991 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:22:08 +0200 Subject: [PATCH] feat: Open maps directly if one map is only available --- lib/widgets/OpenInMaps.dart | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/widgets/OpenInMaps.dart b/lib/widgets/OpenInMaps.dart index 86955424..bfbbd4bc 100644 --- a/lib/widgets/OpenInMaps.dart +++ b/lib/widgets/OpenInMaps.dart @@ -31,6 +31,23 @@ class OpenInMaps extends StatefulWidget { class _OpenInMapsState extends State { Future> mapFuture = MapLauncher.installedMaps; + @override + void initState() { + super.initState(); + + mapFuture.then((maps) { + if (maps.length == 1) { + // No selection to choose from, open directly + final map = maps[0]; + map.showDirections( + destination: widget.destination, + ); + + Navigator.pop(context); + } + }); + } + @override Widget build(BuildContext context) { final l10n = AppLocalizations.of(context); @@ -83,20 +100,22 @@ class _OpenInMapsState extends State { const SizedBox(height: SMALL_SPACE), PlatformListTile( title: Text( - "Lat: ${widget.destination.latitude}, Long: ${widget.destination.longitude}", + "Lat: ${widget.destination.latitude}, Long: ${widget + .destination.longitude}", ), leading: PlatformIconButton( icon: PlatformWidget( material: (_, __) => const Icon(Icons.copy), cupertino: (_, __) => - const Icon(CupertinoIcons.doc_on_clipboard), + const Icon(CupertinoIcons.doc_on_clipboard), ), onPressed: () { // Copy to clipboard Clipboard.setData( ClipboardData( text: - "${widget.destination.latitude}, ${widget.destination.longitude}", + "${widget.destination.latitude}, ${widget + .destination.longitude}", ), ); },