import 'package:flutter/foundation.dart'; import 'package:url_launcher/url_launcher.dart'; /// Hands a destination to the phone's own maps app. /// /// Native intent first, web as the fallback, so a rider gets the same app /// whichever control in Miler he presses. Three screens had their own copy of /// these two URLs — a route row, a map screen and a confirmation sheet — which /// is three chances for one of them to open a different app, or the wrong /// scheme, on the one action a rider takes at every single stop. /// /// Silent on failure by design: there is nothing useful to say to a rider whose /// phone has no maps application, and the screen he pressed from still has the /// address on it. Future openExternalNavigation(double lat, double lng) async { try { final native = Uri.parse('google.navigation:q=$lat,$lng&mode=d'); if (await launchUrl(native, mode: LaunchMode.externalApplication)) return; } catch (_) { // Falls through to the web URL below — a device with no navigation intent // handler is the normal case on iOS, not an error. } try { await launchUrl( Uri.parse( 'https://www.google.com/maps/dir/?api=1' '&destination=$lat,$lng&travelmode=driving', ), mode: LaunchMode.externalApplication, ); } catch (e) { debugPrint('[NAV] could not open maps: $e'); } }