Skip to content

Commit 905822e

Browse files
committed
refactor
0.3.2
1 parent c7d1da3 commit 905822e

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

lib/inherited_model.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ class SharedValueInheritedModel extends InheritedModel<SharedValue> {
1111
@required this.stateNonceMap,
1212
}) : super(key: key, child: child);
1313

14+
// fallback to updateShouldNotifyDependent()
1415
@override
15-
bool updateShouldNotify(InheritedWidget oldWidget) {
16-
return true;
17-
}
16+
bool updateShouldNotify(InheritedWidget oldWidget) => true;
1817

1918
@override
2019
bool updateShouldNotifyDependent(
2120
SharedValueInheritedModel oldWidget,
2221
Set<SharedValue> dependencies,
2322
) {
24-
for (var state in dependencies) {
23+
for (SharedValue sharedValue in dependencies) {
2524
// Compare the nonce value of this SharedValue,
2625
// with an older nonce value of the same SharedValue object.
2726
//
2827
// If the nonce values are not same,
2928
// rebuild the widget
30-
if (state.nonce != oldWidget.stateNonceMap[state]) {
29+
if (sharedValue.nonce != oldWidget.stateNonceMap[sharedValue]) {
3130
return true;
3231
}
3332
}

lib/manager_widget.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class StateManagerWidget extends StatefulWidget {
99
final StateManagerWidgetState state;
1010
final Map<SharedValue, double> stateNonceMap;
1111

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);
1718

1819
@override
1920
StateManagerWidgetState createState() {

lib/shared_value.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class SharedValue<T> {
5353

5454
/// Update [value] and rebuild the dependent widgets if it changed.
5555
set value(T newValue) {
56-
if (newValue == _value) return;
5756
setState(() {
5857
_value = newValue;
5958
});
@@ -74,7 +73,7 @@ class SharedValue<T> {
7473
]);
7574
}
7675

77-
var ret = fn?.call();
76+
R ret = fn?.call();
7877

7978
if (ret is Future) {
8079
ret.then((_) {
@@ -132,16 +131,16 @@ class SharedValue<T> {
132131
/// Else, udpdate [value] and rebuild dependent widgets if it changed.
133132
Future<void> load() async {
134133
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);
137136
if (str == null) return;
138137
value = deserialize(str);
139138
}
140139

141140
/// Store the current [value] at [key] in shared preferences.
142141
Future<void> save() async {
143142
assert(key != null);
144-
var pref = await SharedPreferences.getInstance();
143+
SharedPreferences pref = await SharedPreferences.getInstance();
145144
await pref.setString(key, serialize(_value));
146145
}
147146

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: shared_value
22
description: A straightforward way to manage global state in flutter apps.
3-
version: 0.3.1
3+
version: 0.3.2
44
author: Dev Aggarwal <[email protected]>
55
homepage: https://github.com/pycampers/flutter-global-state
66

0 commit comments

Comments
 (0)