1
    polylines: {
      if (_info != null)
        Polyline(
          polylineId: PolylineId('overview_polyline'),
          width: 5,
          points: _info.polylinePoints
              .map((e) => LatLng(e.latitude, e.longitude))
              .toList(),
        ),
    },

I got an error on the line _info.polylinPoints, but i did make a conditional statement prior to this stating if (_info != null) . My I know why I am still getting the error message?

1 Answer 1

0

Even though you check for the _info not being null, the type is not automatically promoted later since it's not a local variable (I cannot confirm this by looking at this piece of code, but that's quite a common problem). Thus, the compiler still considers for the variable to possibly hold a nullable value.

Since you are aware that the null check is there and _info won't be null, you could easily use the ! operator:

polylines: {
  if (_info != null)
    Polyline(
      polylineId: PolylineId('overview_polyline'),
      width: 5,
          points: _info!.polylinePoints // <-- Notice the ! operator
              .map((e) => LatLng(e.latitude, e.longitude))
              .toList(),
        ),
    },

Check for more information and context here.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.