mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.4k stars 310 forks source link

[Question] No observables detected when checking in a ternary operator inside of a child parameter #953

Closed subzero911 closed 10 months ago

subzero911 commented 11 months ago

I use an Observer like this:

image

Where viewedAt is an Observable inside a Task model:

image

But Observer can't see it for some reason:

image

This error disappears though, if I do reading right in the Observer body:

image

Why is this line style: task.viewedAt.value == null ? styleA : styleB treated like a non-immediate context execution? Does a ternary operator implicitly unfolds into the anonymous function by the compiler?

amondnet commented 11 months ago

@subzero911

This is because showUnseen is not an Observable. If showUnseen is false, conditions after && are not checked.

style: false && store.viewedAt.value != null // store.viewedAt.value is not used
              ? const TextStyle()
              : const TextStyle()
스크린샷 2023-12-07 오전 11 09 43

style: showUnseen && store.viewedAt.value != null -> style: store.viewedAt.value != null && showUnseen