File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,8 @@ class PerAccountStoreWidget extends StatefulWidget {
203203 /// on the server.
204204 ///
205205 /// See also:
206+ /// * [maybeOf] , for a version of this that returns null instead of erroring
207+ /// if there is no [PerAccountStoreWidget] ancestor.
206208 /// * [accountIdOf] , for the account ID corresponding to the same data.
207209 /// * [GlobalStoreWidget.of] , for the app's data beyond that of a
208210 /// particular account.
@@ -213,6 +215,21 @@ class PerAccountStoreWidget extends StatefulWidget {
213215 return widget! .store;
214216 }
215217
218+ /// Like [of] , but returns null instead of erroring if there is no
219+ /// [PerAccountStoreWidget] ancestor.
220+ ///
221+ /// Useful in particular for content widgets that have special functionality
222+ /// when they appear in a per-account context, which is the common case
223+ /// (the message list).
224+ ///
225+ /// This will be useful for #488, supporting Zulip content rendering
226+ /// in e.g. an org description shown before you log in.
227+ // TODO(#488) Remove #488 comment.
228+ static PerAccountStore ? maybeOf (BuildContext context) {
229+ final widget = context.dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
230+ return widget? .store;
231+ }
232+
216233 /// Our account ID for the relevant account for this widget.
217234 ///
218235 /// As with [of] , the data is taken from the closest [PerAccountStoreWidget]
You can’t perform that action at this time.
0 commit comments