Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
feat: Open maps directly if one map is only available
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Sep 26, 2023
1 parent 1827ff0 commit 4e1432f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/widgets/OpenInMaps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ class OpenInMaps extends StatefulWidget {
class _OpenInMapsState extends State<OpenInMaps> {
Future<List<AvailableMap>> 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);
Expand Down Expand Up @@ -83,20 +100,22 @@ class _OpenInMapsState extends State<OpenInMaps> {
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}",
),
);
},
Expand Down

0 comments on commit 4e1432f

Please sign in to comment.