@@ -164,7 +164,7 @@ class PerAccountStoreWidget extends StatefulWidget {
164164 /// * [InheritedNotifier] , which provides the "dependency" mechanism.
165165 static PerAccountStore of (BuildContext context) {
166166 final widget = context.dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
167- assert (widget != null , 'No PerAccountStoreWidget ancestor' );
167+ assert (_debugCheckFound (context, widget) );
168168 return widget! .store;
169169 }
170170
@@ -183,12 +183,29 @@ class PerAccountStoreWidget extends StatefulWidget {
183183 /// Like [of] , the cost of this method is O(1) with a small constant factor.
184184 static int accountIdOf (BuildContext context) {
185185 final element = context.getElementForInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
186- assert (element != null , 'No PerAccountStoreWidget ancestor' );
186+ assert (_debugCheckFound (context, element) );
187187 final widget = element! .findAncestorWidgetOfExactType <PerAccountStoreWidget >();
188188 assert (widget != null );
189189 return widget! .accountId;
190190 }
191191
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+
192209 /// Whether there is a relevant account specified for this widget.
193210 static bool debugExistsOf (BuildContext context) {
194211 return context.getElementForInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >() != null ;
0 commit comments