diff --git a/lib/main.dart b/lib/main.dart index c3c3aaf1685b318f99ceb5974e3207da79475f29..78136d0f88bf96b7cb41c0db5456a3528f4139d6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,7 @@ import 'widgets/returnDestination.dart'; import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart'; import 'package:http/http.dart' as http; +import 'dart:async'; import 'dart:convert'; import 'package:weather_icons/weather_icons.dart'; import 'config/config.dart'; @@ -90,6 +91,7 @@ class _MyHomePageState extends State<MyHomePage> { // Weather API var _forecastList = []; bool _isCollapsed = false; + bool _isLoading = false; // Format input text. String getFormattedText(String inputText) { @@ -164,9 +166,16 @@ class _MyHomePageState extends State<MyHomePage> { // -----------Section For Map Operations, Coords, Polyline..---------------- // Get shortest path. void _getShortestPath() async { - _getWeather(); _resetPolyline(); - _getDirections(); + + _isLoading = true; + + await Future.wait<void>([ + _getWeather(), + _getDirections(), + ]); + + _isLoading = false; } // Add markers for origin/dest coords. @@ -222,7 +231,7 @@ class _MyHomePageState extends State<MyHomePage> { } // Get coords between origin/dest points corresponding to shortest path. - void _getDirections() async { + Future<void> _getDirections() async { _resetPolyline(); try { var originlat = _originCoordinates.latitude; @@ -682,7 +691,7 @@ class _MyHomePageState extends State<MyHomePage> { // ----------Section For Getting Weather Data------------ // Create weather query to the external weather API - void _getWeather() async { + Future<void> _getWeather() async { _forecastList = []; setState(() { _forecastList; @@ -1024,7 +1033,7 @@ class _MyHomePageState extends State<MyHomePage> { itemBuilder: (BuildContext context, int index) { return Stack( children: [ - Column( + _isLoading ? Center(child: const CircularProgressIndicator()) : Column( children: [ Container( margin: EdgeInsets.only(bottom: 15, top: 5),