Skip to content

Instantly share code, notes, and snippets.

@deidyomega
Created March 25, 2018 22:58
Show Gist options
  • Save deidyomega/949c79a27a1aadacdfd629322fdfcbe4 to your computer and use it in GitHub Desktop.
Save deidyomega/949c79a27a1aadacdfd629322fdfcbe4 to your computer and use it in GitHub Desktop.
For article on mattharris.tech
// Import the JS interop library
import 'dart:js';
// export the js wrapper as the function you want, since I'm only exporting one, i used the handy => notation.
void main() => context['adder'] = jsAdder;
// This wraps adder, returning the object we created, now I made it return a map, since that's usually more useful.
Object jsAdder(num a,num b) {
return new JsObject.jsify(adder(a, b));
}
// This pure dart function, called, adder, takes two numbers and returns their result in an object.
Map<String, num> adder(num a, num b) {
Map<String, num> output = {
'result': a+b
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment