@@ -132,16 +132,38 @@ class PerAccountStoreWidget extends StatefulWidget {
132132 /// [BuildContext.dependOnInheritedWidgetOfExactType] .
133133 ///
134134 /// See also:
135- /// * [InheritedNotifier ] , which provides the "dependency" mechanism .
135+ /// * [accountIdOf ] , for the account ID corresponding to the same data .
136136 /// * [GlobalStoreWidget.of] , for the app's data beyond that of a
137137 /// particular account.
138+ /// * [InheritedNotifier] , which provides the "dependency" mechanism.
138139 static PerAccountStore of (BuildContext context) {
139140 final widget = context
140141 .dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
141142 assert (widget != null , 'No PerAccountStoreWidget ancestor' );
142143 return widget! .store;
143144 }
144145
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+
145167 @override
146168 State <PerAccountStoreWidget > createState () => _PerAccountStoreWidgetState ();
147169}
0 commit comments