Skip to content

Commit

Permalink
Remove scrollController and onOffsetChange
Browse files Browse the repository at this point in the history
  • Loading branch information
peng8350 committed May 7, 2021
1 parent 33effd7 commit d221d3f
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 74 deletions.
4 changes: 0 additions & 4 deletions example/lib/other/refresh_recordable_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class RefreshReorderableListView extends StatefulWidget {

final Function onRefresh, onLoading;

final Function onOffsetChange;

final RefreshController refreshController;

Expand All @@ -77,7 +76,6 @@ class RefreshReorderableListView extends StatefulWidget {
this.enablePullUp: false,
this.onRefresh,
this.onLoading,
this.onOffsetChange,
}) : assert(scrollDirection != null),
assert(onReorder != null),
assert(children != null),
Expand Down Expand Up @@ -162,7 +160,6 @@ class _ReorderableListViewState extends State<RefreshReorderableListView> {
enablePullUp: widget.enablePullUp,
refreshFooter: widget.refreshFooter,
refreshHeader: widget.refreshHeader,
onOffsetChange: widget.onOffsetChange,
onLoading: widget.onLoading,
onRefresh: widget.onRefresh,
);
Expand Down Expand Up @@ -647,7 +644,6 @@ class _ReorderableListContentState extends State<_ReorderableListContent>
enablePullUp: widget.enablePullUp,
footer: widget.refreshFooter,
header: widget.refreshHeader,
onOffsetChange: widget.onOffsetChange,
onLoading: widget.onLoading,
onRefresh: widget.onRefresh,
);
Expand Down
1 change: 0 additions & 1 deletion example/lib/ui/test/Test1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Test1State extends State<Test1> {
});
});
},
onOffsetChange: _onOffsetCallback,
child: ListView.builder(
itemExtent: 100.0,
itemCount: data.length,
Expand Down
1 change: 0 additions & 1 deletion example/lib/ui/test/Test2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class _Test2State extends State<Test2> with TickerProviderStateMixin {
onRefresh: _onRefresh,
header: MaterialClassicHeader(),
onLoading: _onLoading,
onOffsetChange: _onOffsetCallback,
child: GridView.builder(
primary: false,
gridDelegate:
Expand Down
3 changes: 0 additions & 3 deletions lib/src/internals/indicator_wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,6 @@ mixin IndicatorStateMixin<T extends StatefulWidget, V> on State<T> {
if (overscrollPast < 0.0) {
return;
}
if (refresher!.onOffsetChange != null) {
refresher!.onOffsetChange!(V == RefreshStatus, overscrollPast);
}
_dispatchModeByOffset(overscrollPast);
}

Expand Down
24 changes: 2 additions & 22 deletions lib/src/smart_refresher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import 'indicator/material_indicator.dart';
// ignore_for_file: INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER
// ignore_for_file: DEPRECATED_MEMBER_USE

/// callback when the indicator scroll out of edge
/// up: indicate header or footer callback
/// offset: the distance of indicator out of edge
typedef void OnOffsetChange(bool up, double offset);

/// when viewport not full one page, for different state,whether it should follow the content
typedef bool ShouldFollowContent(LoadStatus? status);
Expand Down Expand Up @@ -171,9 +167,6 @@ class SmartRefresher extends StatefulWidget {
/// If you want to close twoLevel,you should use [RefreshController.closeTwoLevel]
final VoidCallback? onTwoLevel;

/// callback when the indicator scroll out of edge
final OnOffsetChange? onOffsetChange;

/// Controll inner state
final RefreshController controller;

Expand Down Expand Up @@ -224,7 +217,6 @@ class SmartRefresher extends StatefulWidget {
this.onRefresh,
this.onLoading,
this.onTwoLevel,
this.onOffsetChange,
this.dragStartBehavior,
this.primary,
this.cacheExtent,
Expand Down Expand Up @@ -253,7 +245,7 @@ class SmartRefresher extends StatefulWidget {
this.onRefresh,
this.onLoading,
this.onTwoLevel,
this.onOffsetChange})
})
: header = null,
footer = null,
child = null,
Expand Down Expand Up @@ -411,14 +403,7 @@ class SmartRefresherState extends State<SmartRefresher> {
clipBehavior = clipBehavior ?? childView.clipBehavior;
scrollController = scrollController ?? childView.controller;

// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
widget.controller.scrollController = scrollController ??
childView.controller ??
(childView.primary ? PrimaryScrollController.of(context) : null);
} else {
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
widget.controller.scrollController =
PrimaryScrollController.of(context);

}
body = CustomScrollView(
// ignore: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
Expand Down Expand Up @@ -584,11 +569,6 @@ class RefreshController {
/// the value is get when the header or footer callback onPositionUpdated
ScrollPosition? position;

/// deprecated member,not suggest to use it,it contain share position bug
@Deprecated(
'advice set ScrollController to child,use it directly will cause bug when call jumpTo() and animateTo()')
ScrollController? scrollController;

RefreshStatus? get headerStatus => headerMode?.value;

LoadStatus? get footerStatus => footerMode?.value;
Expand Down
46 changes: 3 additions & 43 deletions test/smart_refresher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,56 +210,16 @@ void main() {
logs.clear();
_refreshController.loadComplete();

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: SmartRefresher(
header: TestHeader(),
footer: TestFooter(),
enablePullDown: true,
enablePullUp: true,
child: ListView.builder(
itemBuilder: (c, i) => Center(
child: Text(data[i]),
),
itemCount: 20,
itemExtent: 100,
),
onOffsetChange: (up, offset) {
logs.add(offset);
},
controller: _refreshController,
),
));

// check onOffsetChange(top)
_refreshController.position!.jumpTo(0.0);
double count = 1;
while (count < 11) {
await tester.drag(find.byType(Scrollable), Offset(0, 20),
touchSlopY: 0.0);
count++;
await tester.pump(Duration(milliseconds: 20));
}
for (double i in logs ) {
expect(i, greaterThanOrEqualTo(0));
}
logs.clear();
// check onOffsetChange
_refreshController.position!
.jumpTo(_refreshController.position!.maxScrollExtent);
count = 1;
while (count < 11) {
await tester.drag(find.byType(Scrollable), Offset(0, -20),
touchSlopY: 0.0);
count++;
await tester.pump(Duration(milliseconds: 20));
}
expect(logs.length, greaterThan(0));
for (double i in logs) {
expect(i, greaterThanOrEqualTo(0));
}
logs.clear();
await tester.pump(Duration(milliseconds: 20));



});

testWidgets(" verity smartRefresher and NestedScrollView", (tester) async {
Expand Down

0 comments on commit d221d3f

Please sign in to comment.