Skip to content

fix(species): guard against present-but-null external avatar URL#610

Open
meadowspace-apps wants to merge 1 commit intoMDeLuise:mainfrom
meadowspace-apps:fix-external-species-null-image-guard
Open

fix(species): guard against present-but-null external avatar URL#610
meadowspace-apps wants to merge 1 commit intoMDeLuise:mainfrom
meadowspace-apps:fix-external-species-null-image-guard

Conversation

@meadowspace-apps
Copy link
Copy Markdown

Hey Plant-it community!

This fixes a "null check operator used on a null value" crash that happens when opening the detail view for certain external species — one of the reproducible failure paths encountered while working through #589.

What's new?

In `ViewSpeciesViewModel._loadExternal`, the check `externalAvatarUrl.present` gated a dereference via `.value!`. Drift's `.present` is true whenever a `Value` was explicitly constructed — including `Value(null)`. For species with no `image_url` from FloraCodex, `externalAvatarUrl.value` is null but `.present` is still true, so the `!` threw.

Add an explicit `!= null` check alongside `.present` before the dereference.

Why is it important?

FloraCodex returns `image_url: null` for a meaningful portion of its catalogue (many algae, marine species, obscure genera — easy to hit from a casual "rose" search). Before this change, tapping any such species threw a null-check exception and the user saw a generic "null check operator used on a null value" error instead of the detail page. No image appears on the detail page either way; with the fix, the page just opens without an avatar.

How to Use?

No behavior change for species that do have an image. Species without an image now render their detail screen correctly instead of crashing.

Notes

  • Scope: one conditional in `view_species_viewmodel.dart`, 6 lines changed.
  • Comment added to explain drift's `.present` semantics so the next person doesn't trip on it.
  • `flutter analyze` clean; `flutter test` passes (5/5).
  • Verified on Samsung S21 by tapping several FloraCodex species with and without images.

Refs #589

`_loadExternal` checked `externalAvatarUrl.present` before dereferencing
`externalAvatarUrl.value!`, but drift considers a Value.present when it
was set, even if the contained value is null. FloraCodex returns
species with a null `image_url` often enough (e.g. many algae and
obscure genera) that this would throw:

    type 'Null' is not a subtype of type 'Null' in type cast
    (internally: "Null check operator used on a null value")

Add an explicit null check alongside `.present` so species with no
image simply load without their avatar.
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

Successfully merging this pull request may close these issues.

1 participant