JsModule class final

显式注册到 runtime 的 JavaScript 模块描述。

ES 模块在 JS import name 时加载;CommonJS 模块在通过 JsEngine.runCommonJs 执行 require(name) 时加载。

Constructors

JsModule({required String name, required String? source, JsModuleFormat format = JsModuleFormat.esModule})
使用内联源码创建宿主模块。
const
JsModule.asset({required String name, required String? path, AssetBundle? bundle, JsModuleFormat format = JsModuleFormat.esModule})
使用 Flutter asset 创建宿主模块描述(同步构造)。
const
JsModule.commonJs({required String name, required String source})
创建 ES 格式宿主模块(内联源码)。 创建 CommonJS 格式宿主模块(内联源码)。
const
JsModule.commonJsAsset({required String name, required String path, AssetBundle? bundle})
创建 CommonJS 格式宿主模块(Flutter asset,同步构造)。
const

Properties

bundle → AssetBundle?
解析 path 时使用的 asset bundle。
final
format → JsModuleFormat
模块格式(ES module 或 CommonJS)。
final
hashCode → int
The hash code for this object.
no setterinherited
name → String
JS import 或 require 使用的模块名。
final
path → String?
包含模块源码的 Flutter asset 路径。
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
source → String?
内联模块 JavaScript 源码;与 path 二选一。
final

Methods

loadSource() → Future<String>
加载模块源码:优先返回内联 source,否则从 path 读取 asset。
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