Add exception handling (#8528)

This commit is contained in:
Michael Thomsen
2017-03-02 16:15:52 +01:00
committed by GitHub
parent c9644a49f2
commit 55e10a6630

View File

@@ -17,10 +17,16 @@ class _PlatformServicesState extends State<PlatformServices> {
String _location = 'Unknown location.';
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(() {
_location = 'Latitude ${result[0]}, Longitude ${result[1]}.';
_location = location;
});
}