1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter/scheduler.dart' ;
3
3
4
- import '../model/binding.dart' ;
5
- import '../model/database.dart' ;
6
4
import '../model/settings.dart' ;
7
5
import '../model/store.dart' ;
8
6
import 'page.dart' ;
@@ -15,15 +13,14 @@ import 'page.dart';
15
13
/// * [GlobalStoreWidget.of] , to get access to the data.
16
14
/// * [PerAccountStoreWidget] , for the user's data associated with a
17
15
/// particular Zulip account.
18
- class GlobalStoreWidget extends StatefulWidget {
19
- const GlobalStoreWidget ({
16
+ class GlobalStoreWidget extends InheritedNotifier < GlobalStore > {
17
+ GlobalStoreWidget ({
20
18
super .key,
21
- this .placeholder = const LoadingPlaceholder (),
22
- required this .child,
23
- });
24
-
25
- final Widget placeholder;
26
- final Widget child;
19
+ required GlobalStore store,
20
+ required Widget child,
21
+ }) : super (notifier: store,
22
+ child: _GlobalSettingsStoreInheritedWidget (
23
+ store: store.settings, child: child));
27
24
28
25
/// The app's global data store.
29
26
///
@@ -48,7 +45,7 @@ class GlobalStoreWidget extends StatefulWidget {
48
45
/// * [PerAccountStoreWidget.of] , for the user's data associated with a
49
46
/// particular Zulip account.
50
47
static GlobalStore of (BuildContext context) {
51
- final widget = context.dependOnInheritedWidgetOfExactType <_GlobalStoreInheritedWidget >();
48
+ final widget = context.dependOnInheritedWidgetOfExactType <GlobalStoreWidget >();
52
49
assert (widget != null , 'No GlobalStoreWidget ancestor' );
53
50
return widget! .store;
54
51
}
@@ -75,47 +72,10 @@ class GlobalStoreWidget extends StatefulWidget {
75
72
return widget! .store;
76
73
}
77
74
78
- @override
79
- State <GlobalStoreWidget > createState () => _GlobalStoreWidgetState ();
80
- }
81
-
82
- class _GlobalStoreWidgetState extends State <GlobalStoreWidget > {
83
- GlobalStore ? store;
84
-
85
- @override
86
- void initState () {
87
- super .initState ();
88
- (() async {
89
- final store = await ZulipBinding .instance.getGlobalStoreUniquely ();
90
- setState (() {
91
- this .store = store;
92
- });
93
- })();
94
- }
95
-
96
- @override
97
- Widget build (BuildContext context) {
98
- final store = this .store;
99
- if (store == null ) return widget.placeholder;
100
- return _GlobalStoreInheritedWidget (store: store, child: widget.child);
101
- }
102
- }
103
-
104
- // This is separate from [GlobalStoreWidget] only because we need
105
- // a [StatefulWidget] to get hold of the store, and an [InheritedWidget] to
106
- // provide it to descendants, and one widget can't be both of those.
107
- class _GlobalStoreInheritedWidget extends InheritedNotifier <GlobalStore > {
108
- _GlobalStoreInheritedWidget ({
109
- required GlobalStore store,
110
- required Widget child,
111
- }) : super (notifier: store,
112
- child: _GlobalSettingsStoreInheritedWidget (
113
- store: store.settings, child: child));
114
-
115
75
GlobalStore get store => notifier! ;
116
76
}
117
77
118
- // This is like [_GlobalStoreInheritedWidget ] except it subscribes to the
78
+ // This is like [GlobalStoreWidget ] except it subscribes to the
119
79
// [GlobalSettingsStore] instead of the overall [GlobalStore].
120
80
// That enables [settingsOf] to do the same.
121
81
class _GlobalSettingsStoreInheritedWidget extends InheritedNotifier <GlobalSettingsStore > {
0 commit comments