Skip to content

Commit

Permalink
release 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
peng8350 committed May 11, 2019
1 parent 8117a3b commit 0560741
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 47 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ Notice: This version of the code changes much, Api too
* implements auto hide FooterView when less than one page,no need to set enablePullUp to false
* improve safety after disposed

## 1.3.3
* Fixed the request Refresh problem: Sometimes it takes two times to be effective
* Add child key support
* Fix Bug:Pull-down triggers need to be pulled down more distances to trigger
* Add resetNoData to resume footer state to idle
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you are Chinese,click here([中文文档](https://github.com/peng8350/flutter
```
dependencies:
pull_to_refresh: ^1.3.2
pull_to_refresh: ^1.3.3
```

Expand All @@ -46,6 +46,8 @@ initState(){
super.initState();
_refreshController = RefreshController();
// if you need refreshing when init
// _refreshController.requestRefresh();
}
void _onRefresh(){
Expand Down Expand Up @@ -87,7 +89,8 @@ void dispose(){


## Custom
1.In the first way, assuming that the indicator function you want to implement is not too complex, you can use CustomHeader or CustomFooter
1.In the first way, assuming that the indicator function you want to implement is not too complex, you can use CustomHeader or CustomFooter.
using onOffsetChange callback in SmartRefresher to implements some simple animation.

```
Widget buildHeader(BuildContext context,RefreshStatus mode){
Expand Down
6 changes: 4 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
```
dependencies:
pull_to_refresh: ^1.3.2
pull_to_refresh: ^1.3.3
```

Expand All @@ -42,6 +42,8 @@ initState(){
super.initState();
_refreshController = RefreshController();
// 如果你需要开始就请求一次刷新
// _refreshController.requestRefresh();
}
void _onRefresh(){
Expand Down Expand Up @@ -80,7 +82,7 @@ void dispose(){
```

## 自定义指示器
1.第一种方式,假设你要实现的指示器功能不是太过于复杂,可以使用CustomHeader或者CustomFooter
1.第一种方式,假设你要实现的指示器功能不是太过于复杂,可以使用CustomHeader或者CustomFooter,利用SmartRefresher里的onOffsetChange回调可完成一些简单的动画

```
Widget buildHeader(BuildContext context,RefreshStatus mode){
Expand Down
14 changes: 8 additions & 6 deletions example/lib/ui/test/Example3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Example3State extends State<Example3> with TickerProviderStateMixin {


//test #68
bool _enablePullUp=false,_enablePullDown=false;
bool _enablePullUp=true,_enablePullDown=true;



void _getDatas() {
data.add(Row(children: <Widget>[
FlatButton(onPressed: (){
_refreshController.requestRefresh();
_refreshController.requestRefresh(needDownAnimate: false);
}, child: Text("请求刷新")),
FlatButton(onPressed: (){
_refreshController.requestLoading();
Expand Down Expand Up @@ -114,7 +114,6 @@ class Example3State extends State<Example3> with TickerProviderStateMixin {
//
// });
// });
//
// Future.delayed(Duration(milliseconds: 3000),(){
// _enablePullDown = true;
// _enablePullUp = false;
Expand All @@ -132,8 +131,10 @@ class Example3State extends State<Example3> with TickerProviderStateMixin {
// });
// });
_getDatas();
_scrollController = ScrollController(keepScrollOffset: true);
_refreshController = RefreshController();
// SchedulerBinding.instance.addPostFrameCallback((_){
// _refreshController.requestRefresh(needDownAnimate: false);
// });
super.initState();
}

Expand All @@ -157,8 +158,8 @@ class Example3State extends State<Example3> with TickerProviderStateMixin {
child: Stack(
children: <Widget>[
SmartRefresher(
enablePullUp: true,
enablePullDown: true,
enablePullUp: _enablePullDown,
enablePullDown: _enablePullUp,
controller: _refreshController,
header: WaterDropHeader(waterDropColor: Colors.greenAccent),
footer: ClassicFooter(
Expand All @@ -168,6 +169,7 @@ class Example3State extends State<Example3> with TickerProviderStateMixin {
},
),
onRefresh: () {
print("onRefresh");
Future.delayed(const Duration(milliseconds: 2009)).then((val) {
_refreshController.refreshFailed();
});
Expand Down
40 changes: 16 additions & 24 deletions lib/src/internals/indicator_wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'default_constants.dart';
import 'dart:math' as math;
Expand Down Expand Up @@ -69,6 +68,7 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>
if (overscrollPast < 0.0) {
return;
}

if (refresher.widget.onOffsetChange != null) {
refresher.widget.onOffsetChange(true, overscrollPast);
}
Expand All @@ -87,8 +87,8 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>

// handle the state change between canRefresh and idle canRefresh before refreshing
void handleDragMove(double offset) {

if (floating) return;

if (_scrollController.position.activity.velocity == 0.0) {
if (offset >= widget.triggerDistance) {
mode = RefreshStatus.canRefresh;
Expand All @@ -108,30 +108,21 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>
if (!mounted) {
return;
}

update();
switch (mode) {
case RefreshStatus.refreshing:
floating = true;
if (mode == RefreshStatus.completed || mode == RefreshStatus.failed) {
endRefresh().then((_) {
floating = false;
update();
readyToRefresh().then((_) {
if (refresher.widget.onRefresh != null) refresher.widget.onRefresh();
});
break;
case RefreshStatus.completed:
endRefresh().then((_) {
floating = false;
update();
});

break;
case RefreshStatus.failed:
endRefresh().then((_) {
floating = false;
update();
});
break;
default:
break;
// make gesture release
(_scrollController.position as ScrollActivityDelegate).goIdle();
});
} else if (mode == RefreshStatus.refreshing) {
floating = true;
update();
readyToRefresh().then((_) {
if (refresher.widget.onRefresh != null) refresher.widget.onRefresh();
});
}
}

Expand Down Expand Up @@ -175,6 +166,7 @@ abstract class RefreshIndicatorState<T extends RefreshIndicator>
// TODO: implement initState

_scrollController = refresher.scrollController;

_headerMode = refresher.widget.controller.headerMode;
// it is necessary,sometime the widget may be dispose ,it should be resume the state
_headerMode.value = RefreshStatus.idle;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internals/slivers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _RenderSliverRefresh extends RenderSliver
layoutExtentOffsetCompensation = layoutExtent;
return;
}
final bool active = constraints.overlap <= 0.0 || layoutExtent >= 0.0;
final bool active = constraints.overlap < 0.0 || layoutExtent > 0.0;
final double overscrolledExtent = constraints.overlap.abs();
if (refreshStyle == RefreshStyle.Behind) {
child.layout(
Expand Down
37 changes: 26 additions & 11 deletions lib/src/smart_refresher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,36 @@ class RefreshController {
ScrollController scrollController;
RefreshIndicator _header;

RefreshStatus get headerStatus => headerMode?.value;

LoadStatus get footerStatus => footerMode?.value;

bool get isRefresh => headerMode?.value == RefreshStatus.refreshing;

bool get isLoading => footerMode?.value == LoadStatus.loading;

void requestRefresh(
{bool needDownAnimate: true,
Duration duration: const Duration(milliseconds: 400),
Duration duration: const Duration(milliseconds: 300),
Curve curve: Curves.linear}) {
assert(scrollController != null,
'Try not to call requestRefresh() before build,please call after the ui was rendered');
if (headerStatus == RefreshStatus.idle)
scrollController.animateTo(-_header.triggerDistance,
duration: duration, curve: curve);
if(headerMode?.value !=RefreshStatus.idle)return;
if(needDownAnimate){
scrollController.animateTo(-_header.triggerDistance, duration: duration, curve: curve);
}
else {
headerMode?.value = RefreshStatus.refreshing;
// only afte the header has Layout,else it will generate a bouncing effect
SchedulerBinding.instance.addPostFrameCallback((_){
scrollController.jumpTo(0.0);
});

}
}

void requestLoading(
{Duration duration: const Duration(milliseconds: 200),
{Duration duration: const Duration(milliseconds: 300),
Curve curve: Curves.linear}) {
assert(scrollController != null,
'Try not to call requestLoading() before build,please call after the ui was rendered');
Expand Down Expand Up @@ -210,18 +227,16 @@ class RefreshController {
});
}

void resetNoData() {
footerMode?.value = LoadStatus.idle;
}

void dispose() {
headerMode.dispose();
footerMode.dispose();
headerMode = null;
footerMode = null;
}

RefreshStatus get headerStatus => headerMode?.value;

LoadStatus get footerStatus => footerMode?.value;

bool get isRefresh => headerMode?.value == RefreshStatus.refreshing;

bool get isLoading => footerMode?.value == LoadStatus.loading;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pull_to_refresh
description: a widget provided to the flutter scroll component drop-down refresh and pull up load.
version: 1.3.2
version: 1.3.3
author: Jpeng <peng8350@gmail.com>
homepage: https://github.com/peng8350/flutter_pulltorefresh

Expand Down

0 comments on commit 0560741

Please sign in to comment.