Skip to content

Commit

Permalink
requestPermissionCallback in LocationMarkerDataStreamFactory.defaultP…
Browse files Browse the repository at this point in the history
…ositionStreamSource
  • Loading branch information
tlserver committed Aug 15, 2023
1 parent cf4344f commit c4717f5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/src/data_stream_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import 'exception/permission_denied_exception.dart' as lm;
import 'exception/permission_requesting_exception.dart' as lm;
import 'exception/service_disabled_exception.dart';

/// Signature for callbacks of permission request.
typedef RequestPermissionCallback = FutureOr<LocationPermission> Function();

/// Helper class for converting the data stream which provide data in required
/// format from stream created by some existing plugin.
class LocationMarkerDataStreamFactory {
Expand Down Expand Up @@ -47,7 +50,8 @@ class LocationMarkerDataStreamFactory {
/// Create a position stream which is used as default value of
/// [CurrentLocationLayer.positionStream].
Stream<Position?> defaultPositionStreamSource({
bool shouldRequestPermission = true,
RequestPermissionCallback? requestPermissionCallback =
Geolocator.requestPermission,
}) {
final List<AsyncCallback> cancelFunctions = [];
final streamController = StreamController<Position?>.broadcast(
Expand All @@ -57,11 +61,11 @@ class LocationMarkerDataStreamFactory {
streamController.onListen = () async {
try {
LocationPermission permission = await Geolocator.checkPermission();
if (shouldRequestPermission &&
permission == LocationPermission.denied) {
if (permission == LocationPermission.denied &&
requestPermissionCallback != null) {
streamController.sink
.addError(const lm.PermissionRequestingException());
permission = await Geolocator.requestPermission();
permission = await requestPermissionCallback();
}
switch (permission) {
case LocationPermission.denied:
Expand Down

0 comments on commit c4717f5

Please sign in to comment.