Skip to content
Snippets Groups Projects
Commit 1cc8488c authored by alpes98's avatar alpes98
Browse files

Merge branch 'usability' into 'demo'

Usability improvements

See merge request !3
parents 2fba5d69 fe1a4f91
Branches
No related tags found
2 merge requests!6final project merge into main,!3Usability improvements
...@@ -8,6 +8,7 @@ import 'widgets/returnDestination.dart'; ...@@ -8,6 +8,7 @@ import 'widgets/returnDestination.dart';
import 'package:geocoding/geocoding.dart'; import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:weather_icons/weather_icons.dart'; import 'package:weather_icons/weather_icons.dart';
import 'config/config.dart'; import 'config/config.dart';
...@@ -90,6 +91,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -90,6 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
// Weather API // Weather API
var _forecastList = []; var _forecastList = [];
bool _isCollapsed = false; bool _isCollapsed = false;
bool _isLoading = false;
// Format input text. // Format input text.
String getFormattedText(String inputText) { String getFormattedText(String inputText) {
...@@ -164,9 +166,16 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -164,9 +166,16 @@ class _MyHomePageState extends State<MyHomePage> {
// -----------Section For Map Operations, Coords, Polyline..---------------- // -----------Section For Map Operations, Coords, Polyline..----------------
// Get shortest path. // Get shortest path.
void _getShortestPath() async { void _getShortestPath() async {
_getWeather();
_resetPolyline(); _resetPolyline();
_getDirections();
_isLoading = true;
await Future.wait<void>([
_getWeather(),
_getDirections(),
]);
_isLoading = false;
} }
// Add markers for origin/dest coords. // Add markers for origin/dest coords.
...@@ -206,8 +215,23 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -206,8 +215,23 @@ 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. // Get coords between origin/dest points corresponding to shortest path.
void _getDirections() async { Future<void> _getDirections() async {
_resetPolyline(); _resetPolyline();
try { try {
var originlat = _originCoordinates.latitude; var originlat = _originCoordinates.latitude;
...@@ -228,6 +252,18 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -228,6 +252,18 @@ class _MyHomePageState extends State<MyHomePage> {
}), }),
headers: <String, String>{"Content-Type": "application/json"}); headers: <String, String>{"Content-Type": "application/json"});
_data = jsonDecode(response.body); _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']; var coordinates = _data['route'];
int duration = _data['duration']; int duration = _data['duration'];
int distance = _data['distance']; int distance = _data['distance'];
...@@ -655,7 +691,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -655,7 +691,7 @@ class _MyHomePageState extends State<MyHomePage> {
// ----------Section For Getting Weather Data------------ // ----------Section For Getting Weather Data------------
// Create weather query to the external weather API // Create weather query to the external weather API
void _getWeather() async { Future<void> _getWeather() async {
_forecastList = []; _forecastList = [];
setState(() { setState(() {
_forecastList; _forecastList;
...@@ -997,7 +1033,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -997,7 +1033,7 @@ class _MyHomePageState extends State<MyHomePage> {
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Stack( return Stack(
children: [ children: [
Column( _isLoading ? Center(child: const CircularProgressIndicator()) : Column(
children: [ children: [
Container( Container(
margin: EdgeInsets.only(bottom: 15, top: 5), margin: EdgeInsets.only(bottom: 15, top: 5),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment