diff --git a/examples/platform_services/lib/main.dart b/examples/platform_services/lib/main.dart index aeaf795969..300604a81b 100644 --- a/examples/platform_services/lib/main.dart +++ b/examples/platform_services/lib/main.dart @@ -17,10 +17,16 @@ class _PlatformServicesState extends State { String _location = 'Unknown location.'; Future _getLocation() async { - List result = await platform.invokeMethod('getLocation', 'network'); + String location; + try { + List result = await platform.invokeMethod('getLocation', 'network'); + location = 'Latitude ${result[0]}, Longitude ${result[1]}.'; + } on PlatformException catch (e) { + location = "Failed to get location: '${e.message}'."; + } setState(() { - _location = 'Latitude ${result[0]}, Longitude ${result[1]}.'; + _location = location; }); }