Hi all,
I have a set of elements, defined as:
import 'dart:html';
final loadingDiv = document.querySelector('#loadingDiv');
final documentDiv = document.querySelector('documentDiv');
...
In another file, I want to ensure they're valid (I.E. I've typed the selectors correctly), then operate on them:
void main() {
if (loadingDiv != null && documentDiv != null) {
loadingDiv.hidden = true;
documentDiv.hidden = false;
}
}
When it comes to setting the .hidden properties, I get the error:
error • js\main.dart:5:5 • The property 'hidden' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.') or adding a null check to the target ('!').
• unchecked_use_of_nullable_value
error • js\main.dart:6:5 • The property 'hidden' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.') or adding a null check to the target ('!').
• unchecked_use_of_nullable_value
2 issues found.
I understand what the error is telling me, but surely if the definitions are final, they can't change value? I've read about how fields of a class need to be made local because the compiler can't guarantee that asynchronous code hasn't changed the initial values since your if statements, but final variables?
Thanks in advance.
Take care,
Chris Norman