flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

fix: No ToJson extension and also a few other extensions for LocationData Object

Open Bikuta-victor1 opened this issue 3 years ago • 2 comments

Description A clear and concise description of what the bug is. Have you tried running flutter clean first ?

Expected behavior A clear and concise description of what you expected to happen.

Steps To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Tested on:

  • Android, API Level XX [e.g. 31], simulator or real device
  • iOS, Version XX [e.g. 15], simulator or real device

Other plugins:

  • List of others Flutter plugins that could interfere

Additional logs

some logs

Bikuta-victor1 avatar Sep 13 '22 12:09 Bikuta-victor1

Had the same issue, so had to override the dependency to get the last update that still contained toJson

dependency_overrides: location_platform_interface: 3.0.0

tomosullivan8 avatar Dec 03 '23 20:12 tomosullivan8

Seems like the override above no longer works, so instead I created my own extension which I can call from location.toJson()

extension LocationDataJson on LocationData {
  Map<String, dynamic> toJson() {
    return {
      'latitude': latitude,
      'longitude': longitude,
      'accuracy': accuracy,
      'altitude': altitude,
      'speed': speed,
      'speedAccuracy': speedAccuracy,
      'heading': heading,
      'time': time,
    };
  }
}

tomosullivan8 avatar Jan 05 '24 13:01 tomosullivan8