@@ -164,7 +164,7 @@ class PerAccountStoreWidget extends StatefulWidget {
164
164
/// * [InheritedNotifier] , which provides the "dependency" mechanism.
165
165
static PerAccountStore of (BuildContext context) {
166
166
final widget = context.dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
167
- assert (widget != null , 'No PerAccountStoreWidget ancestor' );
167
+ assert (_debugCheckFound (context, widget) );
168
168
return widget! .store;
169
169
}
170
170
@@ -183,12 +183,29 @@ class PerAccountStoreWidget extends StatefulWidget {
183
183
/// Like [of] , the cost of this method is O(1) with a small constant factor.
184
184
static int accountIdOf (BuildContext context) {
185
185
final element = context.getElementForInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
186
- assert (element != null , 'No PerAccountStoreWidget ancestor' );
186
+ assert (_debugCheckFound (context, element) );
187
187
final widget = element! .findAncestorWidgetOfExactType <PerAccountStoreWidget >();
188
188
assert (widget != null );
189
189
return widget! .accountId;
190
190
}
191
191
192
+ static bool _debugCheckFound (BuildContext context, Object ? ancestor) {
193
+ // Compare [debugCheckHasMediaQuery], and its caller [MediaQuery.of].
194
+ assert (() {
195
+ if (ancestor != null ) return true ;
196
+ throw FlutterError .fromParts ([
197
+ ErrorSummary ('No PerAccountStoreWidget ancestor found.' ),
198
+ ErrorDescription ('${context .widget .runtimeType } widgets require a PerAccountStoreWidget ancestor.' ),
199
+ context.describeWidget ('The specific widget that could not find a PerAccountStoreWidget ancestor was' ),
200
+ context.describeOwnershipChain ('The ownership chain for the affected widget is' ),
201
+ ErrorHint ('For a new page in the app, consider MaterialAccountWidgetRoute '
202
+ 'or AccountPageRouteBuilder.' ),
203
+ ErrorHint ('In tests, consider TestZulipApp with its accountId field.' ),
204
+ ]);
205
+ }());
206
+ return true ;
207
+ }
208
+
192
209
/// Whether there is a relevant account specified for this widget.
193
210
static bool debugExistsOf (BuildContext context) {
194
211
return context.getElementForInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >() != null ;
0 commit comments