Skip to content
Snippets Groups Projects
Commit 7f58a895 authored by Filip Dalüge's avatar Filip Dalüge
Browse files

Display error messages

parent 2fba5d69
No related branches found
No related tags found
2 merge requests!6final project merge into main,!3Usability improvements
......@@ -206,6 +206,21 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
void _showMessage(String string, BuildContext context) {
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
content: Text(string),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, 'OK'),
child: const Text('OK'),
),
],
),
);
}
// Get coords between origin/dest points corresponding to shortest path.
void _getDirections() async {
_resetPolyline();
......@@ -228,6 +243,18 @@ class _MyHomePageState extends State<MyHomePage> {
}),
headers: <String, String>{"Content-Type": "application/json"});
_data = jsonDecode(response.body);
if (_data.containsKey('error_code') && _data['error_code'] != 0) {
switch(_data['error_code']) {
case 1:
_showMessage('The address is outside the solution space. Please enter an address within Berlin-Brandenburg.', context);
return;
case 2:
_showMessage('The address could not be found.', context);
return;
}
}
var coordinates = _data['route'];
int duration = _data['duration'];
int distance = _data['distance'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment