EmbeddedJsContent class
Declares some Javascript content (usually a function) which will be embedded ("burned") into the HTML source at runtime.
Note: One should try to use functions as much as possible, and avoid "raw" javascript.
Now there are two modes in which you can use this: ("js") or ("mobileJs" and "webJs")
The "js" param should be used when the JS function you are trying to embed doesn't call any DartCallbacks or interact in any way with the Dart side, or when it does interact but it's nothing platform-specific.
Simply put, "js" is only for pure Javascript stuff or crossplatform calls.
Example what to declare in "js":
EmbeddedJsContent(
js: 'function sayHi() {
console.log('hi');
}'
),
Both "mobileJs" and "webJs" should be used when the JS function you are trying to embed WILL call platform-dependent DartCallbacks and/or interact with the Dart side.
Note
: If you set one of them, you must set the other too, even if it will not be used.
If you don't need it, just set it to an empty string.
Note 2
: If you use "mobileJs" and "webJs", don't use "js" too. Use only one of them.
If you want to call a platform-dependent Dart callback inside a function, you should define the function twice (for "mobileJs" and "webJs") and call the callback using platform-specific syntax, like this:
For MOBILE
:
Some_Callback_Name.postMessage(param1, param2...);
For WEB
:
Some_Callback_Name(param1, param2...);
Example what to declare in both "mobileJs" and "webJs":
EmbeddedJsContent(
mobileJs: 'function callDartCallback() {
Some_Callback_Name.postMessage('hi');
}',
webJs: 'function callDartCallback() {
Some_Callback_Name('hi');
}',
),
Constructors
- EmbeddedJsContent({String? js, String? mobileJs, String? webJs})
-
Constructor
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- js → String?
-
This param should be used when the JS you wish to define
doesn't interact in any way with the Dart side
final
- mobileJs → String?
-
This (and webJs) param should be used when the JS you wish to define
does interact with the Dart side
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- webJs → String?
-
This (and mobileJs) param should be used when the JS you wish to define
does interact with the Dart side
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited