@@ -132,16 +132,38 @@ class PerAccountStoreWidget extends StatefulWidget {
132
132
/// [BuildContext.dependOnInheritedWidgetOfExactType] .
133
133
///
134
134
/// See also:
135
- /// * [InheritedNotifier ] , which provides the "dependency" mechanism .
135
+ /// * [accountIdOf ] , for the account ID corresponding to the same data .
136
136
/// * [GlobalStoreWidget.of] , for the app's data beyond that of a
137
137
/// particular account.
138
+ /// * [InheritedNotifier] , which provides the "dependency" mechanism.
138
139
static PerAccountStore of (BuildContext context) {
139
140
final widget = context
140
141
.dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
141
142
assert (widget != null , 'No PerAccountStoreWidget ancestor' );
142
143
return widget! .store;
143
144
}
144
145
146
+ /// Our account ID for the relevant account for this widget.
147
+ ///
148
+ /// As with [of] , the data is taken from the closest [PerAccountStoreWidget]
149
+ /// that encloses the given context. Throws an error if there is no enclosing
150
+ /// [PerAccountStoreWidget] .
151
+ ///
152
+ /// Unlike [of] , this method does not create a dependency relationship, and
153
+ /// updates to the [PerAccountStoreWidget] will not cause the calling widget
154
+ /// to be rebuilt. As a result, this should not be called from build methods,
155
+ /// but is appropriate to use in interaction event handlers. For more, see
156
+ /// [BuildContext.findAncestorWidgetOfExactType] .
157
+ ///
158
+ /// Like [of] , the cost of this method is O(1) with a small constant factor.
159
+ static int accountIdOf (BuildContext context) {
160
+ final element = context.getElementForInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
161
+ assert (element != null , 'No PerAccountStoreWidget ancestor' );
162
+ final widget = element! .findAncestorWidgetOfExactType <PerAccountStoreWidget >();
163
+ assert (widget != null );
164
+ return widget! .accountId;
165
+ }
166
+
145
167
@override
146
168
State <PerAccountStoreWidget > createState () => _PerAccountStoreWidgetState ();
147
169
}
0 commit comments