Search code examples
htmldartdart2js

Select() method returns a warning


I need a Select All button for a textarea. It works with this code, but I get a warning from Dart2js:

querySelector('#select-all-button').onClick.listen((e) {
//e.preventDefault();
querySelector('#textarea-target').select();
});

Warning: No method named 'select' in class 'Element'.
  querySelector('#textarea-target').select();
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why?


Solution

  • The return type of querySelector() is dynamic AFAIR. You need to explicitly tell the analyzer what type this will return

    (document.querySelector('textarea') as TextAreaElement).select();
    

    Try it on DartPad