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

I have an error using the null safety version #13

Open
PaoloP98 opened this issue Apr 30, 2021 · 6 comments
Open

I have an error using the null safety version #13

PaoloP98 opened this issue Apr 30, 2021 · 6 comments

Comments

@PaoloP98
Copy link

I have an error using the null safety version

E/flutter ( 687): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type '(BaseCluster, double, double) => MapMarker' is not a subtype of type '((BaseCluster?, double?, double?) => MapMarker)?'

I initialised the cluster in this way:

      minZoom: minZoom,
      maxZoom: maxZoom,
      radius: 150,
      extent: 4096,
      nodeSize: 64,
      points: markers,
      createCluster: (
        BaseCluster cluster,
        double lng,
        double lat,
      ) =>
          MapMarker(
        id: cluster.id.toString(),
        latitude: lat,
        longitude: lng,
        isCluster: cluster.isCluster,
        clusterId: cluster.id,
        pointsSize: cluster.pointsSize,
        childMarkerId: cluster.childMarkerId,
      ),
    );

Do you know what the problem is?

Originally posted by @PaoloP98 in #12 (comment)

@sunderee
Copy link

sunderee commented May 3, 2021

The problem seems to be related to this line taken out of the official documentation:

...
createCluster: (BaseCluster cluster, double longitude, double latitude) {
    // something here
});
...

If you look at the error message, it tells you that types BaseCluster, and two doubles are nullable. Therefore, you should try replacing what you currently have with

createCluster: (BaseCluster? cluster, double? longitude, double? latitude) {
    // something here
});

Edit: fixed wording.

@PaoloP98
Copy link
Author

PaoloP98 commented May 3, 2021

I tried that but I can't figure out what createCluster should return if cluster equals null

@vishnuraj-dev
Copy link

Same here, did you find any solution.

@PaoloP98
Copy link
Author

PaoloP98 commented Jun 8, 2021

Same here, did you find any solution.

I solved it this way: I added an if to check if the cluster == null and in that case I return a mapmarker without assigning values. The only value I pass is the id because in my constructor is required

return Fluster<MapMarker>(
        minZoom: minZoom,
        maxZoom: maxZoom,
        radius: 150,
        extent: 4096,
        nodeSize: 64,
        points: markers,
        createCluster: (BaseCluster? cluster, double? longitude, double? latitude) {
          if (cluster == null) {
            return MapMarker(id: "");
          }
          return MapMarker(
            id: cluster.id.toString(),
            latitude: latitude,
            longitude: longitude,
            isCluster: cluster.isCluster,
            clusterId: cluster.id,
            pointsSize: cluster.pointsSize,
            childMarkerId: cluster.childMarkerId,
          );
        });

@codepushr
Copy link

@alfonsocejudo Can you maybe update the documentation and elaborate on how to use it if the cluster is nil ?

@digiboridev
Copy link

digiboridev commented Oct 22, 2021

  final Fluster<MapMarker> fluster = Fluster<MapMarker>(
        minZoom: 10, // The min zoom at clusters will show
        maxZoom: 20, // The max zoom at clusters will show
        radius: 150, // Cluster radius in pixels
        extent: 2048, // Tile extent. Radius is calculated with it.
        nodeSize: 64, // Size of the KD-tree leaf node.
        points: newMarkers, // The list of markers created before
        createCluster:
            (BaseCluster? cluster, double? longitude, double? latitude) {
          if (cluster != null) {
            return MapMarker(
              id: cluster.id.toString(),
              position: LatLng(latitude!, longitude!),
              icon: icon,
              isCluster: cluster.isCluster,
              clusterId: cluster.id,
              pointsSize: cluster.pointsSize,
              childMarkerId: cluster.childMarkerId,
            );
          }
        });
class MapMarker extends Clusterable {
  final String id;
  final LatLng position;
  final BitmapDescriptor icon;
  MapMarker({
    required this.id,
    required this.position,
    required this.icon,
    isCluster = false,
    clusterId,
    pointsSize,
    childMarkerId,
  }) : super(
          markerId: id,
          latitude: position.latitude,
          longitude: position.longitude,
          isCluster: isCluster,
          clusterId: clusterId,
          pointsSize: pointsSize,
          childMarkerId: childMarkerId,
        );
  Marker toMarker() => Marker(
        markerId: MarkerId(id),
        position: LatLng(
          position.latitude,
          position.longitude,
        ),
        icon: icon,
      );
}

Unhandled Exception: type '(BaseCluster?, double?, double?) => MapMarker?' is not a subtype of type '((BaseCluster?, double?, double?) => MapMarker)?'

Whats wrong?

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

No branches or pull requests

5 participants