Skip to content

Commit 601e97e

Browse files
author
Kamil Klyta
committed
Introduce null safety
1 parent 20a2d95 commit 601e97e

File tree

6 files changed

+73
-75
lines changed

6 files changed

+73
-75
lines changed

example/pubspec.lock

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.4.2"
10+
version: "2.5.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.0.0"
17+
version: "2.1.0"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.0.0"
24+
version: "1.1.0"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.1.3"
31+
version: "1.2.0"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "1.0.1"
38+
version: "1.1.0"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.14.13"
45+
version: "1.15.0"
4646
confetti:
4747
dependency: "direct main"
4848
description:
@@ -51,7 +51,7 @@ packages:
5151
source: hosted
5252
version: "0.4.0"
5353
custom_refresh_indicator:
54-
dependency: "direct dev"
54+
dependency: "direct main"
5555
description:
5656
path: ".."
5757
relative: true
@@ -63,7 +63,7 @@ packages:
6363
name: fake_async
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "1.1.0"
66+
version: "1.2.0"
6767
flutter:
6868
dependency: "direct main"
6969
description: flutter
@@ -80,21 +80,21 @@ packages:
8080
name: matcher
8181
url: "https://pub.dartlang.org"
8282
source: hosted
83-
version: "0.12.8"
83+
version: "0.12.10"
8484
meta:
8585
dependency: transitive
8686
description:
8787
name: meta
8888
url: "https://pub.dartlang.org"
8989
source: hosted
90-
version: "1.1.8"
90+
version: "1.3.0"
9191
path:
9292
dependency: transitive
9393
description:
9494
name: path
9595
url: "https://pub.dartlang.org"
9696
source: hosted
97-
version: "1.7.0"
97+
version: "1.8.0"
9898
random_color:
9999
dependency: transitive
100100
description:
@@ -113,55 +113,55 @@ packages:
113113
name: source_span
114114
url: "https://pub.dartlang.org"
115115
source: hosted
116-
version: "1.7.0"
116+
version: "1.8.0"
117117
stack_trace:
118118
dependency: transitive
119119
description:
120120
name: stack_trace
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "1.9.5"
123+
version: "1.10.0"
124124
stream_channel:
125125
dependency: transitive
126126
description:
127127
name: stream_channel
128128
url: "https://pub.dartlang.org"
129129
source: hosted
130-
version: "2.0.0"
130+
version: "2.1.0"
131131
string_scanner:
132132
dependency: transitive
133133
description:
134134
name: string_scanner
135135
url: "https://pub.dartlang.org"
136136
source: hosted
137-
version: "1.0.5"
137+
version: "1.1.0"
138138
term_glyph:
139139
dependency: transitive
140140
description:
141141
name: term_glyph
142142
url: "https://pub.dartlang.org"
143143
source: hosted
144-
version: "1.1.0"
144+
version: "1.2.0"
145145
test_api:
146146
dependency: transitive
147147
description:
148148
name: test_api
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151-
version: "0.2.17"
151+
version: "0.2.19"
152152
typed_data:
153153
dependency: transitive
154154
description:
155155
name: typed_data
156156
url: "https://pub.dartlang.org"
157157
source: hosted
158-
version: "1.2.0"
158+
version: "1.3.0"
159159
vector_math:
160160
dependency: transitive
161161
description:
162162
name: vector_math
163163
url: "https://pub.dartlang.org"
164164
source: hosted
165-
version: "2.0.8"
165+
version: "2.1.0"
166166
sdks:
167-
dart: ">=2.9.0-14.0.dev <3.0.0"
167+
dart: ">=2.12.0-0.0 <3.0.0"

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ dependencies:
1010
flutter:
1111
sdk: flutter
1212
confetti: 0.4.0
13+
custom_refresh_indicator:
14+
path: ../
1315

1416
dev_dependencies:
1517
flutter_test:
1618
sdk: flutter
17-
custom_refresh_indicator:
18-
path: ../
1919

2020
flutter:
2121
uses-material-design: true

lib/src/controller.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ class IndicatorController extends ChangeNotifier {
6161

6262
/// Creates [CustomRefreshIndicator] controller class
6363
factory IndicatorController({
64-
bool refreshEnabled,
64+
bool? refreshEnabled,
6565
}) =>
6666
IndicatorController._(refreshEnabled: refreshEnabled);
6767

6868
IndicatorController._({
69-
double value,
70-
AxisDirection direction,
71-
ScrollDirection scrollingDirection,
72-
IndicatorState state,
73-
bool refreshEnabled,
69+
double? value,
70+
AxisDirection? direction,
71+
ScrollDirection? scrollingDirection,
72+
IndicatorState? state,
73+
bool? refreshEnabled,
7474
}) : _currentState = state ?? IndicatorState.idle,
7575
_previousState = state ?? IndicatorState.idle,
7676
_scrollingDirection = scrollingDirection ?? ScrollDirection.idle,
@@ -181,10 +181,10 @@ class IndicatorController extends ChangeNotifier {
181181
}
182182

183183
/// Returns `true` when state did change [from] to [to].
184-
bool didStateChange({IndicatorState from, IndicatorState to}) {
184+
bool didStateChange({IndicatorState? from, IndicatorState? to}) {
185185
final stateChanged = _previousState != _currentState;
186-
if (to == null) return _previousState == from && stateChanged;
187-
if (from == null) return _currentState == to && stateChanged;
186+
if (to == null && from != null) return _previousState == from && stateChanged;
187+
if (to != null && from == null ) return _currentState == to && stateChanged;
188188
if (to == null && from == null) return stateChanged;
189189
return _previousState == from && _currentState == to;
190190
}

lib/src/custom_refresh_indicator.dart

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CustomRefreshIndicator extends StatefulWidget {
2727
final Duration loadingToIdleDuration;
2828

2929
/// {@macro custom_refresh_indicator.complete_state}
30-
final Duration completeStateDuration;
30+
final Duration? completeStateDuration;
3131

3232
/// A check that specifies whether a [ScrollNotification] should be
3333
/// handled by this widget.
@@ -43,11 +43,11 @@ class CustomRefreshIndicator extends StatefulWidget {
4343
final bool trailingGlowVisible;
4444

4545
/// Number of pixels that user should drag to change [IndicatorState] from idle to armed.
46-
final double offsetToArmed;
46+
final double? offsetToArmed;
4747

4848
/// Value from 0.0 to 1.0 that describes the percentage of scroll container extent
4949
/// that user should drag to change [IndicatorState] from idle to armed.
50-
final double extentPercentageToArmed;
50+
final double? extentPercentageToArmed;
5151

5252
/// Part of widget tree that contains scrollable element (like ListView).
5353
/// Scroll notifications from the first scrollable element will be used
@@ -79,13 +79,13 @@ class CustomRefreshIndicator extends StatefulWidget {
7979
/// The indicator controller will be passed as the third argument to the [builder] method.
8080
///
8181
/// To better understand this data, look at example app.
82-
final IndicatorController controller;
82+
final IndicatorController? controller;
8383

8484
CustomRefreshIndicator({
85-
Key key,
86-
@required this.child,
87-
@required this.onRefresh,
88-
@required this.builder,
85+
Key? key,
86+
required this.child,
87+
required this.onRefresh,
88+
required this.builder,
8989
this.notificationPredicate = defaultScrollNotificationPredicate,
9090
this.controller,
9191
this.offsetToArmed,
@@ -96,9 +96,7 @@ class CustomRefreshIndicator extends StatefulWidget {
9696
this.completeStateDuration,
9797
this.leadingGlowVisible = false,
9898
this.trailingGlowVisible = true,
99-
}) : assert(child != null, '`child` argument cannot be null.'),
100-
assert(builder != null, '`builder` argument cannot be null.'),
101-
assert(
99+
}) : assert(
102100
extentPercentageToArmed == null || offsetToArmed == null,
103101
'Providing `extentPercentageToArmed` argument take no effect when `offsetToArmed` is provided. '
104102
'Remove redundant argument.',
@@ -120,10 +118,10 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
120118
__canStart = canStart;
121119
}
122120

123-
double _dragOffset;
121+
late double _dragOffset;
124122

125-
AnimationController _animationController;
126-
IndicatorController _customRefreshIndicatorController;
123+
late AnimationController _animationController;
124+
late IndicatorController _customRefreshIndicatorController;
127125

128126
/// Current [IndicatorController]
129127
IndicatorController get controller => _customRefreshIndicatorController;
@@ -157,11 +155,8 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
157155
}
158156

159157
/// Notifies the listeners of the controller
160-
void _updateCustomRefreshIndicatorValue() {
161-
_customRefreshIndicatorController._setValue(
162-
_animationController?.value ?? _kInitialValue,
163-
);
164-
}
158+
void _updateCustomRefreshIndicatorValue() =>
159+
_customRefreshIndicatorController._setValue(_animationController.value);
165160

166161
bool _handleGlowNotification(OverscrollIndicatorNotification notification) {
167162
if (notification.depth != 0) return false;
@@ -190,7 +185,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
190185
if (notification.metrics.extentBefore > 0.0) {
191186
_hide();
192187
} else {
193-
_dragOffset -= notification.scrollDelta;
188+
_dragOffset -= notification.scrollDelta!;
194189
_calculateDragOffset(notification.metrics.viewportDimension);
195190
}
196191
if (controller.state == IndicatorState.armed &&
@@ -229,10 +224,12 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
229224

230225
double newValue;
231226

227+
final offsetToArmed = widget.offsetToArmed;
228+
232229
/// If [offestToArmed] is provided then it will be used otherwise
233230
/// [extentPercentageToArmed]
234-
if (widget.offsetToArmed != null) {
235-
newValue = _dragOffset / widget.offsetToArmed;
231+
if (offsetToArmed != null) {
232+
newValue = _dragOffset / offsetToArmed;
236233
} else {
237234
final extentPercentageToArmed = widget.extentPercentageToArmed ??
238235
CustomRefreshIndicator.defaultExtentPercentageToArmed;
@@ -281,9 +278,10 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
281278
if (!mounted) return;
282279

283280
/// optional complete state
284-
if (widget.completeStateDuration != null) {
281+
final completeStateDuration = widget.completeStateDuration;
282+
if (completeStateDuration != null) {
285283
controller._setIndicatorState(IndicatorState.complete);
286-
await Future.delayed(widget.completeStateDuration);
284+
await Future.delayed(completeStateDuration);
287285
}
288286

289287
if (!mounted) return;

0 commit comments

Comments
 (0)