File tree Expand file tree Collapse file tree 4 files changed +15
-16
lines changed Expand file tree Collapse file tree 4 files changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -11,23 +11,22 @@ class SharedValueInheritedModel extends InheritedModel<SharedValue> {
11
11
@required this .stateNonceMap,
12
12
}) : super (key: key, child: child);
13
13
14
+ // fallback to updateShouldNotifyDependent()
14
15
@override
15
- bool updateShouldNotify (InheritedWidget oldWidget) {
16
- return true ;
17
- }
16
+ bool updateShouldNotify (InheritedWidget oldWidget) => true ;
18
17
19
18
@override
20
19
bool updateShouldNotifyDependent (
21
20
SharedValueInheritedModel oldWidget,
22
21
Set <SharedValue > dependencies,
23
22
) {
24
- for (var state in dependencies) {
23
+ for (SharedValue sharedValue in dependencies) {
25
24
// Compare the nonce value of this SharedValue,
26
25
// with an older nonce value of the same SharedValue object.
27
26
//
28
27
// If the nonce values are not same,
29
28
// rebuild the widget
30
- if (state .nonce != oldWidget.stateNonceMap[state ]) {
29
+ if (sharedValue .nonce != oldWidget.stateNonceMap[sharedValue ]) {
31
30
return true ;
32
31
}
33
32
}
Original file line number Diff line number Diff line change @@ -9,11 +9,12 @@ class StateManagerWidget extends StatefulWidget {
9
9
final StateManagerWidgetState state;
10
10
final Map <SharedValue , double > stateNonceMap;
11
11
12
- const StateManagerWidget (this .child,
13
- this .state,
14
- this .stateNonceMap, {
15
- Key key,
16
- }) : super (key: key);
12
+ const StateManagerWidget (
13
+ this .child,
14
+ this .state,
15
+ this .stateNonceMap, {
16
+ Key key,
17
+ }) : super (key: key);
17
18
18
19
@override
19
20
StateManagerWidgetState createState () {
Original file line number Diff line number Diff line change @@ -53,7 +53,6 @@ class SharedValue<T> {
53
53
54
54
/// Update [value] and rebuild the dependent widgets if it changed.
55
55
set value (T newValue) {
56
- if (newValue == _value) return ;
57
56
setState (() {
58
57
_value = newValue;
59
58
});
@@ -74,7 +73,7 @@ class SharedValue<T> {
74
73
]);
75
74
}
76
75
77
- var ret = fn? .call ();
76
+ R ret = fn? .call ();
78
77
79
78
if (ret is Future ) {
80
79
ret.then ((_) {
@@ -132,16 +131,16 @@ class SharedValue<T> {
132
131
/// Else, udpdate [value] and rebuild dependent widgets if it changed.
133
132
Future <void > load () async {
134
133
assert (key != null );
135
- var pref = await SharedPreferences .getInstance ();
136
- var str = pref.getString (key);
134
+ SharedPreferences pref = await SharedPreferences .getInstance ();
135
+ String str = pref.getString (key);
137
136
if (str == null ) return ;
138
137
value = deserialize (str);
139
138
}
140
139
141
140
/// Store the current [value] at [key] in shared preferences.
142
141
Future <void > save () async {
143
142
assert (key != null );
144
- var pref = await SharedPreferences .getInstance ();
143
+ SharedPreferences pref = await SharedPreferences .getInstance ();
145
144
await pref.setString (key, serialize (_value));
146
145
}
147
146
Original file line number Diff line number Diff line change 1
1
name : shared_value
2
2
description : A straightforward way to manage global state in flutter apps.
3
- version : 0.3.1
3
+ version : 0.3.2
4
4
author :
Dev Aggarwal <[email protected] >
5
5
homepage : https://github.com/pycampers/flutter-global-state
6
6
You can’t perform that action at this time.
0 commit comments