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

Not providing an initialPosition and denying location access throws assertion error #12

Closed
nstrelow opened this issue Feb 24, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@nstrelow
Copy link

Describe the bug
Tested on Android 10 with example from this repo.
When not specifying an initialPosition and opening the PlacePicker Android asks for location permission. Pressing deny throws an assertion error.

To Reproduce
Steps to reproduce the behavior:

  1. Do not specify initialPosition
  2. Deny location permissions
  3. Open PlacePicker

Expected behavior
Be able to deny location permission without errors.

Error log

I/flutter (17053): PlatformException(PERMISSION_DENIED, Access to location data denied, null)

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building Selector<PlaceProvider, MapType>(dirty, dependencies: [_DefaultInheritedProviderScope<PlaceProvider>], state: _Selector0State<MapType>#6739e):
'package:google_maps_flutter/src/camera.dart': Failed assertion: line 22 pos 16: 'target != null': is not true.

The relevant error-causing widget was: 
  PlacePicker file:///C:/Users/nilss/projects/google_maps_place_picker/example/lib/main.dart:76:32
When the exception was thrown, this was the stack: 
#2      new CameraPosition (package:google_maps_flutter/src/camera.dart:22:16)
#3      GoogleMapPlacePicker._buildGoogleMap.<anonymous closure> (package:google_maps_place_picker/src/google_map_place_picker.dart:138:15)
#4      _Selector0State.buildWithChild (package:provider/src/selector.dart)
#5      SingleChildState.build (package:nested/nested.dart:318:41)
#6      StatefulElement.build (package:flutter/src/widgets/framework.dart:4440:27)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor -v

[√] Flutter (Channel beta, v1.14.6, on Microsoft Windows [Version 10.0.19569.1000], locale de-DE)
    • Flutter version 1.14.6 at C:\Users\nilss\flutter
    • Framework revision fabeb2a16f (4 weeks ago), 2020-01-28 07:56:51 -0800
    • Engine revision c4229bfbba
    • Dart version 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\nilss\AppData\Local\Android\Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-R, build-tools 29.0.3
    • ANDROID_SDK_ROOT = C:\Users\nilss\AppData\Local\Android\Sdk
    • Java binary at: C:\Users\nilss\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6137316\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] Android Studio (version 3.6)
    • Android Studio at C:\Users\nilss\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\192.6186006
    • Flutter plugin version 43.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] Connected device (3 available)
    • Android SDK built for x86 64 • emulator-5554 • android-x64    • Android 10 (API 29) (emulator)
@fysoul17
Copy link
Owner

fysoul17 commented Feb 25, 2020

It is working as intended and this scenario should be prevented actually.
I will change [initialPosition] to be required in the next update as it needs to be.

The map needs to be initialised with at least one location (required by GoogleMap), which would be either [initialPosition] or [currentLocation = useCurrentLocation(true)] with GPS. So, if you want users to make sure they use their GSP for the initial map location, I would suggest you to use permission handling package and lead them to the device setting screen if they deny it.

So, in summary, the initial position is a sort of back-up solution for the scenario that we cannot fetch current location from the user, and thus initial position should be set as default.

Does it make sense? ;)

@fysoul17 fysoul17 added the documentation Improvements or additions to documentation label Feb 25, 2020
@nstrelow
Copy link
Author

I will change [initialPosition] to be required in the next update as it needs to be.
Exactly what I thought 😁
Thanks for adding it!

@fysoul17
Copy link
Owner

@nstrelow Glad to hear that ;) Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants