Dart import show window results in NoSuchMethodError


I was trying to use the new show syntax to reduce the size of the compiled js code. This works fine as long as I don’t need any kind of window events.

When I add window to show then, the editor says everything is fine. When I then run the application I get:

Exception: NoSuchMethodError : method not found: 'get:window'
Receiver: Instance of 'Toolbar'
Arguments: []
Stack Trace: #0      Object._noSuchMethod (dart:core-patch:1261:3)
#1      Object.noSuchMethod (dart:core-patch:1264:25)
#2      Toolbar._init (...toolbar.dart:93:5)
#3      Toolbar.Toolbar.initialize (...toolbar.dart:47:10)
#4      main (...toolbar.dart:29:21)

Is there any other way to get a window instance without using window variable?


Are you sure using show actually helps with the size of the compiled JavaScript code? You shouldn’t need to do that. Thanks to tree shaking and dead code elimination, only what you use will show up in the compiled output.

You use show to have tight control over what you import that way it’s obvious what things are coming from what libraries. If you import a lot of libraries without using show, it’s hard to tell what’s coming from where, which can be a challenge with very large codebases.

You can also use show if you import two different libraries that have functions or classes that use the same name. By using show, you can specify which one you want.

Answered By – Shannon -jj Behrens

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *