Baseflow / Baseflow/flutter-geolocator

[Bug]: Position stream neither closes nor emits if location permission is later enabled

Open
#1,301 1 comment 4 reactions 0 assignees View on GitHub
P2 platform: android type: bug
Dominant language
Dart
Stars
1.3k
Forks
803
Avg merge
8h 16m
Merged PRs (30d)
1

Description

### Please check the following before submitting a new issue.

- [X] I have searched the [existing issues](https://github.com/baseflow/flutter-geolocator/issues).
- [X] I have carefully [read the documentation](https://github.com/Baseflow/flutter-geolocator/blob/main/geolocator/README.md) and verified I have added the required platform specific configuration.

### Please select affected platform(s)

- [X] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows

### Steps to reproduce

The issue I've encountered is when the app starts to listen to the position stream without the location permission but is granted this permission some time later by the user. I'd expect the position sream to either close or to start emitting positions when the permission is granted but nothing happens.

On an android device use a fresh install of the application (the application does not have permission access)
1. Start listening to `getPositionStream`
2. ask the user to grant the permission (using `requestlocationPermission` or `permission_handler` package)
3. The user selects either `whileInUse` or `aske every time`

### Expected results

I'd expect the position stream to either close or to start emitting positions when the permission is granted.

### Actual results

Nothing happens and the stream stays open and idle.

The problem I've found with this behavior is there is no way to know whether or not the stream will start emitting positions at some point. And we have no way of consistently displaying an information of what is happening to the user as other `positionStream` errors do end up in the stream emitting locations again when the problem is fixed.

### Code sample

Code sample

```dart
Geolocator.getPositionStream(
locationSettings: AndroidSettings(
distanceFilter: 0,
intervalDuration: const Duration(milliseconds: 500),
accuracy: LocationAccuracy.best,
foregroundNotificationConfig: ForegroundNotificationConfig(
notificationTitle: 'title',
notificationText: 'text',
),
),
).listen(
(event) {
log(event.toString());
},
onError: (e, s) {
log('Stream error', error: e, stackTrace: s);
},
onDone: () {
log('Done');
}
);
Geolocator.requestPermission();
```

Output

```console
[log] Stream error
User denied permissions to access the device's location.
```

### Screenshots or video

Screenshots or video demonstration

[Upload media here]

### Version

9.0.2

### Flutter Doctor output

Doctor output

```console
[!] Flutter (Channel stable, 3.10.6, on Microsoft Windows [version 10.0.22621.1992], locale fr-FR)
• Flutter version 3.10.6 on channel stable at C:\Users\scoar\fvm\versions\3.10.6
! Warning: `dart` on your path resolves to C:\tools\dart-sdk\bin\dart.exe, which is not inside your current Flutter SDK checkout at C:\Users\scoar\fvm\versions\3.10.6. Consider adding C:\Users\scoar\fvm\versions\3.10.6\bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f468f3366c (4 weeks ago), 2023-07-12 15:19:05 -0700
• Engine revision cdbeda788a
• Dart version 3.0.6
• DevTools version 2.23.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at C:\Users\scoar\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.1
• Java binary at: C:\Users\scoar\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\223.8836.35.2231.10406996\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2022.2)
• Android Studio at C:\Users\scoar\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\222.4459.24.2221.10121639
• Flutter plugin version 74.0.2
• Dart plugin version 222.4582
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] Android Studio (version 2022.3)
• Android Studio at C:\Users\scoar\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\223.8836.35.2231.10406996
• Flutter plugin version 74.0.3
• Dart plugin version 223.8950
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] Connected device (4 available)
• sdk gphone x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [version 10.0.22621.1992]
• Chrome (web) • chrome • web-javascript • Google Chrome 115.0.5790.110
• Edge (web) • edge • web-javascript • Microsoft Edge 115.0.1901.188

[√] Network resources
• All expected network resources are available.

! Doctor found issues in 2 categories.

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Android case using getPositionStream before calling requestPermission, then trace the Android stream and permission-handling entry points. Verify the behavior for denied-then-granted permission and define done as the stream either emitting positions or closing with an observable error after permission changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart, flutter
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.