Component class
Marks a class as an island component that can be hydrated on the client.
Components are interactive elements within pages that get hydrated (become interactive) on the client side. They use Custom Elements and Declarative Shadow DOM for instant rendering.
Usage
@Component(tag: 'my-counter')
class Counter extends WebComponent {
@override
String get tagName => 'my-counter';
static String render({int start = 0}) {
return '''
<my-counter start="$start">
<template shadowrootmode="open">
<button>Count: <span id="val">$start</span></button>
</template>
</my-counter>
''';
}
@override
void onMount() {
final btn = query('button')!;
final val = query('#val')!;
var count = propInt('start');
btn.onClick.listen((_) {
count++;
val.text = count.toString();
});
}
}
The component will be automatically registered for hydration based on which pages use it.
Constructors
Properties
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