Created
March 25, 2018 22:58
-
-
Save deidyomega/949c79a27a1aadacdfd629322fdfcbe4 to your computer and use it in GitHub Desktop.
For article on mattharris.tech
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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