universal_html
universal_html copied to clipboard
`HtmlDocument`'s `visibilityState` is `String?` when compiling tests.
Please refer to this repository: https://github.com/harkairt/test_compile_error especially this line
Steps:
- clone the repository
-
fvm use
(or simply use a global flutter 3.16.5) -
flutter pub get && flutter run -d 'chrome'
- works well, the app runs, and if you switch to a new tab, the proper message is written to debug console
-
flutter test
- ❌
Error: Method 'toTabVisibilityChangeEvent' cannot be called on 'String?' because it is potentially null. Try calling using ?. instead.
- if you switch out the commenting of these two lines
- ❌
final event = document.visibilityState.toTabVisibilityChangeEvent();
// final event = (document.visibilityState ?? '').toTabVisibilityChangeEvent();
- then executing the test again will succeed ✅
note: the IDE will warn about unnecessary fallback ''
since it recognizes visibilityState
to be String
and not String?