@@ -2,11 +2,41 @@ import 'package:flutter/material.dart';
2
2
3
3
import '../model/store.dart' ;
4
4
5
+ /// Provides access to the app's data.
6
+ ///
7
+ /// There should be one of this widget, near the root of the tree.
8
+ ///
9
+ /// See also:
10
+ /// * [GlobalStoreWidget.of] , to get access to the data.
11
+ /// * [PerAccountStoreWidget] , for the user's data associated with a
12
+ /// particular Zulip account.
5
13
class GlobalStoreWidget extends StatefulWidget {
6
14
const GlobalStoreWidget ({super .key, required this .child});
7
15
8
16
final Widget child;
9
17
18
+ /// The app's global data store.
19
+ ///
20
+ /// The given build context will be registered as a dependency of the
21
+ /// store. This means that when the data in the store changes,
22
+ /// the element at that build context will be rebuilt.
23
+ ///
24
+ /// This method is typically called near the top of a build method or a
25
+ /// [State.didChangeDependencies] method, like so:
26
+ /// ```
27
+ /// @override
28
+ /// Widget build(BuildContext context) {
29
+ /// final globalStore = GlobalStoreWidget.of(context);
30
+ /// ```
31
+ ///
32
+ /// This method should not be called from a [State.initState] method;
33
+ /// use [State.didChangeDependencies] instead. For discussion, see
34
+ /// [BuildContext.dependOnInheritedWidgetOfExactType] .
35
+ ///
36
+ /// See also:
37
+ /// * [InheritedNotifier] , which provides the "dependency" mechanism.
38
+ /// * [PerAccountStoreWidget.of] , for the user's data associated with a
39
+ /// particular Zulip account.
10
40
static GlobalStore of (BuildContext context) {
11
41
final widget = context
12
42
.dependOnInheritedWidgetOfExactType <_GlobalStoreInheritedWidget >();
@@ -56,13 +86,55 @@ class _GlobalStoreInheritedWidget extends InheritedNotifier<GlobalStore> {
56
86
store != oldWidget.store;
57
87
}
58
88
89
+ /// Provides access to the user's data for a particular Zulip account.
90
+ ///
91
+ /// Widgets that need information that comes from the Zulip server, or need to
92
+ /// interact with the Zulip server, should use [PerAccountStoreWidget.of] to get
93
+ /// the [PerAccountStore] for the relevant account.
94
+ ///
95
+ /// A page that is all about a single Zulip account (which includes most of
96
+ /// the pages in the app) should have one of this widget, near the root of
97
+ /// the page's tree. Where the UI shows information from several accounts,
98
+ /// this widget can be used to specify the account that each subtree should
99
+ /// interact with.
100
+ ///
101
+ /// See also:
102
+ /// * [PerAccountStoreWidget.of] , to get access to the data.
103
+ /// * [GlobalStoreWidget] , for the app's data beyond that of a
104
+ /// particular account.
59
105
class PerAccountStoreWidget extends StatefulWidget {
60
106
const PerAccountStoreWidget (
61
107
{super .key, required this .accountId, required this .child});
62
108
63
109
final int accountId;
64
110
final Widget child;
65
111
112
+ /// The user's data for the relevant Zulip account for this widget.
113
+ ///
114
+ /// The data is taken from the closest [PerAccountStoreWidget] that encloses
115
+ /// the given context. Throws an error if there is no enclosing
116
+ /// [PerAccountStoreWidget] .
117
+ ///
118
+ /// The given build context will be registered as a dependency of the
119
+ /// returned store. This means that when the data in the store changes,
120
+ /// the element at that build context will be rebuilt.
121
+ ///
122
+ /// This method is typically called near the top of a build method or a
123
+ /// [State.didChangeDependencies] method, like so:
124
+ /// ```
125
+ /// @override
126
+ /// Widget build(BuildContext context) {
127
+ /// final store = PerAccountStoreWidget.of(context);
128
+ /// ```
129
+ ///
130
+ /// This method should not be called from a [State.initState] method;
131
+ /// use [State.didChangeDependencies] instead. For discussion, see
132
+ /// [BuildContext.dependOnInheritedWidgetOfExactType] .
133
+ ///
134
+ /// See also:
135
+ /// * [InheritedNotifier] , which provides the "dependency" mechanism.
136
+ /// * [GlobalStoreWidget.of] , for the app's data beyond that of a
137
+ /// particular account.
66
138
static PerAccountStore of (BuildContext context) {
67
139
final widget = context
68
140
.dependOnInheritedWidgetOfExactType <_PerAccountStoreInheritedWidget >();
0 commit comments