Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Quality of Life updates #44

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions lib/src/location_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class _FlutterLocationPickerState extends State<FlutterLocationPicker>
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
Expand Down Expand Up @@ -361,7 +362,7 @@ class _FlutterLocationPickerState extends State<FlutterLocationPicker>
}
// 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
Expand Down Expand Up @@ -696,21 +697,37 @@ class _FlutterLocationPickerState extends State<FlutterLocationPicker>
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;
});
},
);
},
child:
Icon(Icons.my_location, color: widget.locationButtonsColor),
).onError((error, stackTrace) {
print(error);
print(stackTrace);
setState(() {
loadingCurrentLocation = false;
});
},);
} : null,
child: !loadingCurrentLocation
? Icon(Icons.my_location, color: widget.locationButtonsColor)
: CircularProgressIndicator(
color: widget.locationButtonsColor ??
Theme.of(context)
.floatingActionButtonTheme
.foregroundColor ??
Theme.of(context).colorScheme.onSecondary,
),
),
],
),
Expand Down