Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.
This repository was archived by the owner on May 8, 2023. It is now read-only.

Exception thrown when using addMarkers #17

Description

@dimitri-berges
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (23709): The following NoSuchMethodError was thrown building StreamBuilder<int>(dirty, state:
I/flutter (23709): _StreamBuilderBaseState<int, AsyncSnapshot<int>>#4edd9):
I/flutter (23709): The method 'call' was called on null.
I/flutter (23709): Receiver: null
I/flutter (23709): Tried calling: call()
I/flutter (23709):
I/flutter (23709): The relevant error-causing widget was:
I/flutter (23709):   StreamBuilder<int>
I/flutter (23709):   file:///C:/Users/Dixmi/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_map-0.9.0/lib/src/layer/marker_layer.dart:110:12
I/flutter (23709):
I/flutter (23709): When the exception was thrown, this was the stack:
I/flutter (23709): #0      MarkerLayer.build.<anonymous closure> (package:flutter_map/src/layer/marker_layer.dart:134:39)
I/flutter (23709): #1      StreamBuilder.build (package:flutter/src/widgets/async.dart:509:81)
I/flutter (23709): #2      _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:127:48)
I/flutter (23709): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
I/flutter (23709): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
I/flutter (23709): #5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
I/flutter (23709): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
I/flutter (23709): #7      StatefulElement.update (package:flutter/src/widgets/framework.dart:4707:5)
I/flutter (23709): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:3201:15)
I/flutter (23709): #9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
I/flutter (23709): #10     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
I/flutter (23709): #11     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
I/flutter (23709): #12     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:20)
I/flutter (23709): #13     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
I/flutter (23709): #14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
I/flutter (23709): #15     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
I/flutter (23709): #16     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:861:7)
I/flutter (23709): (elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
I/flutter (23709):
I/flutter (23709): ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter doctor -v
[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [version 10.0.18363.959], locale  
    fr-FR)
    • Flutter version 1.17.5 at D:\Lib\flutter
    • Framework revision 8af6b2f038 (5 weeks ago), 2020-06-30 12:53:55 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4

 
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\Dixmi\AppData\Local\Android\sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.0)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin version 48.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
    • Redmi Note 8T • 141e86a0 • android-arm64 • Android 9 (API 28)

• No issues found!

I have this exception every times I try to add multiples markers at once.

Here is a part of the code I use :

var usersObject = Users.fromJson(Map<String, dynamic>.from(jsonDecode(users)));
setState(() {
   mapController.addMarkers(markers: usersObject.toMarkers());
});

And this is the Users class :

class Users {
  Users(this.names, this.locations);
  factory Users.fromJson(Map<String, dynamic> json) {
    var names = json.keys.toList();
    var locations = <Location>[];
    json.forEach((key, value) {
      locations.add(Location(
          latitude: value['latitude'],
          longitude: value['longitude'],
          accuracy: value['accuracy']));
    });
    return Users(names, locations);
  }

  List<String> names;
  List<Location> locations;

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    names.forEach((element) {
      var index = names.indexOf(element);
      map.addAll({
        element: {
          'latitude': locations[index].latitude,
          'longitude': locations[index].longitude,
          'accuracy': locations[index].accuracy,
        }
      });
    });
    return map;
  }

  Map<String, Marker> toMarkers() {
    var map = <String, Marker>{};
    names.forEach((element) {
      var index = names.indexOf(element);
      map.addAll({
        element: Marker(
            point:
                LatLng(locations[index].latitude, locations[index].longitude))
      });
    });
    return map;
  }
}

JSON Pattern :

{
  "Test 2":
    {
      "latitude": <value>,
      "longitude": <value>,
      "accuracy": <value>
    },
  "Test":
    {
      "latitude": <value>,
      "longitude": <value>,
      "accuracy": <value>
    },
  "Test 3":
    {
      "latitude": <value>,
      "longitude": <value>,
      "accuracy": <value>
    }
}

I'm using Location from background_location but values are the same.
For LatLng I'm using latlong.dart

Is anyone can help me on this plz ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions