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

[Bug]: Linux: Position's timestamp can't be required #1371

Closed
3 of 8 tasks
NeroThroN opened this issue Nov 9, 2023 · 2 comments
Closed
3 of 8 tasks

[Bug]: Linux: Position's timestamp can't be required #1371

NeroThroN opened this issue Nov 9, 2023 · 2 comments
Assignees
Labels
P1 High-priority issues at the top of the work list. platform: linux Issue is related to the Linux platform. type: bug Something isn't working

Comments

@NeroThroN
Copy link

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

  1. Install geolocator and geolocator_linux
  2. Build the app for the linux target : flutter build linux
  3. Error while building linux application

Expected results

  1. Install geolocator and geolocator_linux
  2. Build the app for the linux target : flutter build linux
  3. Build successfully

Actual results

ERROR: ../../../../.pub-cache/hosted/pub.dev/geolocator_linux-0.2.0/lib/src/geoclue_x.dart:26:18: Error: The argument type 'DateTime?' can't be assigned to the parameter type 'DateTime' because 'DateTime?' is nullable and 'DateTime' isn't.
ERROR:  - 'DateTime' is from 'dart:core'.
ERROR:       timestamp: timestamp,
ERROR:                  ^
ERROR: Target kernel_snapshot failed: Exception
Building Linux application...                                           
Build process failed

Code sample

Linked to #1145

Because the new geolocator_platform_interface (4.2.0) has remove the fact that timestamp is optional (#1362), the geolocator_linux (0.2.0) cannot build because of this code snippet:

// geolocator_linux/lib/src/geoclue_x.dart
extension GeoCluePosition on GeoClueLocation {
  Position toPosition() {
    return Position(
      accuracy: accuracy,
      altitude: altitude ?? 0,
      altitudeAccuracy: 0,
      heading: heading ?? 0,
      headingAccuracy: 0,
      latitude: latitude,
      longitude: longitude,
      timestamp: timestamp,  // <== Error: The argument type 'DateTime?' can't be assigned to the parameter type 'DateTime' because 'DateTime?' is nullable and 'DateTime' isn't.
      speed: speed ?? 0,
      speedAccuracy: 0,
    );
  }
}

Inside the geoclue package that is used under the hood, the timestamp value is indeed nullable, creating this error

Maybe assigning a default value to timestamp during toPosition could be a solution?

extension GeoCluePosition on GeoClueLocation {
  Position toPosition() {
    return Position(
      accuracy: accuracy,
      altitude: altitude ?? 0,
      altitudeAccuracy: 0,
      heading: heading ?? 0,
      headingAccuracy: 0,
      latitude: latitude,
      longitude: longitude,
      timestamp: timestamp ?? DateTime.now(),
      speed: speed ?? 0,
      speedAccuracy: 0,
    );
  }
}

Screenshots or video

No response

Version

geolocator_linux: 0.2.0 | geolocator: 10.1.0 | geolocator_platform_interface: 4.2.0

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.17.0-5.0.pre.20, on Fedora Linux 39 (Workstation Edition) 6.5.10-300.fc39.x86_64, locale en_US.UTF-8)
    • Flutter version 3.17.0-5.0.pre.20 on channel master at /home/nerothron/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 94550c6257 (10 hours ago), 2023-11-08 19:46:25 -0800
    • Engine revision 8b490a9f16
    • Dart version 3.3.0 (build 3.3.0-107.0.dev)
    • DevTools version 2.30.0-dev.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/nerothron/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /var/lib/snapd/snap/android-studio/128/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /var/lib/flatpak/app/com.google.Chrome/x86_64/stable/active/export/bin/com.google.Chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 17.0.3 (Fedora 17.0.3-1.fc39)
    • cmake version 3.27.7
    • ninja version 1.11.1
    • pkg-config version 1.9.5

[✓] Android Studio (version 2022.3)
    • Android Studio at /var/lib/snapd/snap/android-studio/128/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.84.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.76.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Fedora Linux 39 (Workstation Edition) 6.5.10-300.fc39.x86_64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 119.0.6045.123 unknown

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

• No issues found!
@TimHoogstrate TimHoogstrate self-assigned this Nov 13, 2023
@mvanbeusekom mvanbeusekom self-assigned this Nov 13, 2023
@mvanbeusekom mvanbeusekom added type: bug Something isn't working platform: linux Issue is related to the Linux platform. P1 High-priority issues at the top of the work list. labels Nov 13, 2023
@TimHoogstrate TimHoogstrate removed their assignment Nov 13, 2023
@NeroThroN
Copy link
Author

Have to add the code below to fix the build regression. Because even on android the error inside geolocator_linux was throwed. So to be able to build again on linux and android, forcing geolocator_platform_interface to 4.1.1 works as a temporal fix.

dependency_overrides:
  geolocator_platform_interface: 4.1.1

@NeroThroN
Copy link
Author

Fix with geolocator_linux: 0.2.0+1. Thanks ! 💙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High-priority issues at the top of the work list. platform: linux Issue is related to the Linux platform. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants