Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do I get this error: _CastError (Null check operator used on a null value)

I have a column like this:

  Column(children: [
    product.videos![product.videoIndex].videoUrl != null &&
            product.videos![product.videoIndex].videoUrl != ""
        ? VideoPlayerWidget(
            videoAddress: product.videos![product.videoIndex].videoUrl)
        : Image.asset('assets/images/video-placeholder.jpg'),
  ]),

And I get this error:

_CastError (Null check operator used on a null value)

I know that the variables may be null and that’s the reason I put them within a null check if statement, but I don’t know why do I get the null check error and how can I pass that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The Flutter forced me to put ! after null variables, then it gives me error because of that!

>Solution :

Looks your product.videos itself null. So change ! to ? in if condition.

Column(children: [
    product.videos?[product.videoIndex].videoUrl != null &&
            product.videos?[product.videoIndex].videoUrl != ""
        ? VideoPlayerWidget(
            videoAddress: product.videos![product.videoIndex].videoUrl)
        : Image.asset('assets/images/video-placeholder.jpg'),
  ]),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading