AbBuilder<C extends AbController> class
class Controller extends AbController {
final Ab<int> count = 0.ab;
}
创建控制器并使用
class XXX extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AbBuilder<Controller>(
controller: Controller(),
tag: tag,
builder: (Controller controller, Abw<Controller> abw){
return Text(controller.count.get(abw).toString);
}
);
}
}
如果控制器已被创建过,则直接这样做:
class XXX extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AbBuilder<Controller>(
builder: (Controller controller, Abw<Controller> abw){
return Text(controller.count.get(abw).toString);
}
);
}
}
如果要使用多个 controller,则可以使用嵌套的方式:
class XXX extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AbBuilder(
controller OneController(),
builder: (OneController one, Abw<OneController> oneAbw){
return AbBuilder(
controller TwoController(),
builder: (TwoController two, Abw<TwoController> twoAbw){
return Column(
children: [
Text(one.count.get(oneAbw).toString),
Text(two.count.get(twoAbw).toString),
]
);
}
);
}
);
}
}
controller 禁止使用 Aber.find, 只能用构造函数进行创建,例如: controller: Aber.find
主要目的是为了保证当前 widget 与当前 controller 的生命周期相对应(比如 initState/dispose):
- 如果在父 AbBuilder 中创建了 controller,子 AbBuilder find 了这个父 controller,
- 那么子 AbBuilder 被销毁时,不会将这个父 controller 销毁,
- 只有在父 AbBuilder 被销毁时,才会将这个父 controller 销毁。
- 也就是说,controller 在 AWidget 中被创建,只有当该 AWidget 被销毁时,它才会被自动销毁。
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- AbBuilder
Constructors
Properties
-
builder
→ Widget Function(C controller, Abw<
C> abw) -
final
- controller → C?
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tag → String?
-
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< AbBuilder< C> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited