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

addLine results in Null check operator used on a null value #358

Open
Matix-Media opened this issue Dec 12, 2023 · 2 comments
Open

addLine results in Null check operator used on a null value #358

Matix-Media opened this issue Dec 12, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Matix-Media
Copy link

I am currently trying to add lines to my map, but whenever I try that I get following error in my console:

E/flutter ( 9956): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter ( 9956): #0      MaplibreMapController.addLine (package:maplibre_gl/src/controller.dart:805:22)
E/flutter ( 9956): #1      _ActiveRideCardState.build.<anonymous closure>.<anonymous closure> (package:fahrtenbuch_flutter/widgets/active_ride_card.dart:64:42)
E/flutter ( 9956): #2      _MaplibreMapState.onPlatformViewCreated (package:maplibre_gl/src/maplibre_map.dart:335:27)
E/flutter ( 9956): <asynchronous suspension>

This is the code for adding a new line;

                    onMapCreated: (controller) async {
                      OwnActiveRide activeRide = ridesStore.activeRide as OwnActiveRide;
                      LatLng? lastCheckpoint;
                      
                      for (LatLng checkpoint in activeRide.checkpoints) {
                        if (lastCheckpoint == null) {
                          lastCheckpoint = checkpoint;
                          continue;
                        }

                        print("Adding line from ${lastCheckpoint.toString()} to ${checkpoint.toString()}");
                        await controller.addLine(LineOptions(
                          draggable: false,
                          lineColor: "#ffffff",
                          lineWidth: 15,
                          geometry: [
                            lastCheckpoint,
                            checkpoint
                          ]
                        ));

                        lastCheckpoint = checkpoint;
                      }
@m0nac0
Copy link
Collaborator

m0nac0 commented Dec 13, 2023

Does this happen before or after the onStyleLoadedCallback has fired?

@Matix-Media
Copy link
Author

Matix-Media commented Dec 15, 2023

Okay, so I moved the line code into onStyleLoadedCallback. And now it works. It is weird to setup though, since I have to export the controller out of the onMapCreated (callback) to use it in the onStyleLoadedCallback.

Edit: Nvm, I can just attach the callback to the controller directly.

@josxha josxha added the bug Something isn't working label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants