Calling a global function
suggest changeSuppose we’d like to invoke the JavaScript function JSON.stringify which receives an object, encodes it into a JSON string and returns it.
All we’d have to do is write the function signature, mark it as external and annotate it with the @JS annotation:
import 'package:js/js.dart';
@JS("JSON.stringify")
external String stringify(Object? obj);
The @JS annotation names the JavaScript function this declaration calls. The same annotation marks Dart classes that wrap JavaScript classes.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents