Commit 55e10a66 authored by Michael Thomsen's avatar Michael Thomsen Committed by GitHub

Add exception handling (#8528)

parent c9644a49
...@@ -17,10 +17,16 @@ class _PlatformServicesState extends State<PlatformServices> { ...@@ -17,10 +17,16 @@ class _PlatformServicesState extends State<PlatformServices> {
String _location = 'Unknown location.'; String _location = 'Unknown location.';
Future<Null> _getLocation() async { Future<Null> _getLocation() async {
List<double> result = await platform.invokeMethod('getLocation', 'network'); String location;
try {
List<double> 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(() { setState(() {
_location = 'Latitude ${result[0]}, Longitude ${result[1]}.'; _location = location;
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment