From e2ae9331b14224752d23a7ae6fa16f308819e63a Mon Sep 17 00:00:00 2001 From: CoocooFroggy <45371102+CoocooFroggy@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:42:22 -0500 Subject: [PATCH 1/3] Add loading indicator for current position button Add timeout to fetching current location --- lib/src/location_picker.dart | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/src/location_picker.dart b/lib/src/location_picker.dart index 08a6067..5967e08 100644 --- a/lib/src/location_picker.dart +++ b/lib/src/location_picker.dart @@ -304,6 +304,7 @@ class _FlutterLocationPickerState extends State LatLong initPosition = const LatLong(30.0443879, 31.2357257); Timer? _debounce; bool isLoading = true; + bool loadingCurrentLocation = false; late void Function(Exception e) onError; /// It returns true if the text is RTL, false if it's LTR @@ -361,7 +362,7 @@ class _FlutterLocationPickerState extends State } // When we reach here, permissions are granted and we can // continue accessing the position of the device. - return await Geolocator.getCurrentPosition(); + return await Geolocator.getCurrentPosition(timeLimit: const Duration(seconds: 10)); } /// Create a animation controller, add a listener to the controller, and @@ -696,21 +697,30 @@ class _FlutterLocationPickerState extends State FloatingActionButton( heroTag: "btn3", backgroundColor: widget.locationButtonBackgroundColor, - onPressed: () async { - // setState(() { - // isLoading = true; - // }); + onPressed: !loadingCurrentLocation ? () { + setState(() { + loadingCurrentLocation = true; + }); _determinePosition().then( (currentPosition) { LatLong center = LatLong( currentPosition.latitude, currentPosition.longitude); _animatedMapMove(center.toLatLng(), 18); onLocationChanged(center); + setState(() { + loadingCurrentLocation = false; + }); }, - ); - }, + ).onError((error, stackTrace) { + print(error); + print(stackTrace); + setState(() { + loadingCurrentLocation = false; + }); + },); + } : null, child: - Icon(Icons.my_location, color: widget.locationButtonsColor), + !loadingCurrentLocation ? Icon(Icons.my_location, color: widget.locationButtonsColor) : const CircularProgressIndicator(), ), ], ), From f05d35feaccede767528d21d4ebb2014b4c5a76f Mon Sep 17 00:00:00 2001 From: CoocooFroggy <45371102+CoocooFroggy@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:52:45 -0500 Subject: [PATCH 2/3] Same color --- lib/src/location_picker.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/location_picker.dart b/lib/src/location_picker.dart index 5967e08..a165ee9 100644 --- a/lib/src/location_picker.dart +++ b/lib/src/location_picker.dart @@ -720,7 +720,7 @@ class _FlutterLocationPickerState extends State },); } : null, child: - !loadingCurrentLocation ? Icon(Icons.my_location, color: widget.locationButtonsColor) : const CircularProgressIndicator(), + !loadingCurrentLocation ? Icon(Icons.my_location, color: widget.locationButtonsColor) : CircularProgressIndicator(color: widget.locationButtonsColor,), ), ], ), From 348ec0616675e12261aad04f9c0731f2a40cf5ec Mon Sep 17 00:00:00 2001 From: CoocooFroggy <45371102+CoocooFroggy@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:10:34 -0500 Subject: [PATCH 3/3] Same color --- lib/src/location_picker.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/location_picker.dart b/lib/src/location_picker.dart index a165ee9..17d01de 100644 --- a/lib/src/location_picker.dart +++ b/lib/src/location_picker.dart @@ -719,8 +719,15 @@ class _FlutterLocationPickerState extends State }); },); } : null, - child: - !loadingCurrentLocation ? Icon(Icons.my_location, color: widget.locationButtonsColor) : CircularProgressIndicator(color: widget.locationButtonsColor,), + child: !loadingCurrentLocation + ? Icon(Icons.my_location, color: widget.locationButtonsColor) + : CircularProgressIndicator( + color: widget.locationButtonsColor ?? + Theme.of(context) + .floatingActionButtonTheme + .foregroundColor ?? + Theme.of(context).colorScheme.onSecondary, + ), ), ], ),