AutoStoreWidget class abstract

自动包含 StoreScope 的 StatelessWidget 基类

这个类为无状态组件提供了自动的状态管理能力。 继承此类的组件会自动获得一个独立的 Store 实例, 无需手动包装 StoreScope widget。

使用示例:

class MyPage extends AutoStoreWidget {
  const MyPage({super.key});

  @override
  Widget build(BuildContext context) {
    // 可以直接使用 context.shared() 等方法访问 Store
    final counter = context.shared(counterProvider);
    return Text('Counter: $counter');
  }
}

注意:虽然名为 AutoStoreWidget,但它实际上继承自 AutoStoreStatefulWidget, 这是为了能够管理 Store 的生命周期(创建和销毁)。

Inheritance

Constructors

AutoStoreWidget({Key? key})
const

Properties

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

Methods

build(BuildContext context) Widget
子类需要实现这个方法来构建UI 在这个方法中可以直接使用 context 访问 Store
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<StatefulWidget>
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, int wrapWidth = 65}) 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