Call jQuery Functions from Dart

The standard documentation for Dart and JavaScript interoperability isn’t great. It refers to the ‘dart:js’ library which although works is a bit verbose to get things done.

For instance, to call a jQuery function, you would need

import 'dart:js';
 
...
context.callMethod(r'$', ['.some.class.selector']).callMethod('someFunction');
...

The dart team has since then released the js package with which you can simply call

import 'package:js/js.dart';
 
...
context.$('.some.class.selector').someFunction();
...

Basically native syntax. Of course you have to add it to the yaml and pub get again.