Skip to content

Commit

Permalink
release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peng8350 committed Mar 31, 2019
1 parent 9a98a2a commit 5babb20
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 19 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ Notice: This version of the code changes much, Api too
* Fix refreshIcon not reference in ClassialIndicator

## 1.1.6
* Fix Compile error after flutter update
* Fix Compile error after flutter update


## 1.2.0
* Fixed the problem that ScrollController was not applied to internal controls
* Optimize RefreshController
* RefreshController changed to required now
* Add feature:reuqestRefresh can jumpTo Bottom or Top
* Fix problem: Refresh can still be triggered when ScrollView is nested internally
* Remove rendered twice to get indicator height,replaced by using height attribute in Config
* change RefreshStatus from int to enum
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you are Chinese,click here([中文文档](https://github.com/peng8350/flutter
```
dependencies:
pull_to_refresh: ^1.1.6
pull_to_refresh: ^1.2.0
```

Expand All @@ -39,6 +39,7 @@ If you are Chinese,click here([中文文档](https://github.com/peng8350/flutter
build() =>
new SmartRefresher(
controller:_refreshController,
enablePullDown: true,
enablePullUp: true,
onRefresh: _onRefresh,
Expand All @@ -58,12 +59,16 @@ If you are Chinese,click here([中文文档](https://github.com/peng8350/flutter

3.You should set the indicator according to the different refresh mode.build footer is the same with that.
Of course, I have built an indicator convenient to use, called ClassicIndicator. If I do not meet the requirements, I can choose to define an indicator myself.

Header Config and footer Config can also be set.
Note: The RefreshConfig height here must be exactly the same as the corresponding indicator layout height. (Mainly internal to get indicator height, avoid secondary rendering)
```
Widget _buildHeader(context,mode){
return new ClassicIndicator(mode: mode);
return new Container(
height:50.0,
child:new ClassicIndicator(mode: mode)
);
}
Expand All @@ -75,7 +80,10 @@ Of course, I have built an indicator convenient to use, called ClassicIndicator.
new SmartRefresher(
....
footerBuilder: _buildFooter,
headerBuilder: _buildHeader
headerBuilder: _buildHeader,
// must be exactly the same as the component returned by buildHeader
headerConfig:const RefreshConfig(height:50.0),
footerConfig:const LoadConfig()
)
Expand All @@ -90,6 +98,15 @@ But how can I tell the result to SmartRefresher? It's very simple. It provides a
void _onRefresh(bool up){
if(up){
//headerIndicator callback
/* Note: If headerConfig's autoLoad is turned on, you will have to wait until the next needle is redrawn to update the status, otherwise there will be multiple refreshes.
SchedulerBinding.instance.addPostFrameCallback(
(_){
_refreshController.sendBack(true, RefreshStatus.completed);
}
);
*/
new Future.delayed(const Duration(milliseconds: 2009))
.then((val) {
_refreshController.sendBack(true, RefreshStatus.failed);
Expand All @@ -111,14 +128,14 @@ SmartRefresher:

| Attribute Name | Attribute Explain | Parameter Type | Default Value | requirement |
|---------|--------------------------|:-----:|:-----:|:-----:|
| child | your content View | ? extends ScrollView | null | necessary
| controller | controll inner some states | RefreshController | null | necessary |
| child | your content View | ? extends ScrollView | null | necessary |
| headerBuilder | the header indictor | (BuildContext,int) => Widget | null |if enablePullDown is necessary,else option |
| footerBuilder | the footer indictor | (BuildContext,int) => Widget | null |if enablePullUp is necessary,else option |
| enablePullDown | switch of the pull down | boolean | true | optional |
| enablePullUp | switch of the pull up | boolean | false |optional |
| onRefresh | will callback when the one indicator is getting refreshing | (bool) => Void | null | optional |
| onOffsetChange | callback while you dragging and outOfrange | (bool,double) => Void | null | optional |
| controller | controll inner some states | RefreshController | null | optional |
| headerConfig | This setting will affect which type of indicator you use and config contains a lot props,such as triigerDistance,completedurtion... | Config | RefreshConfig | optional |
| footerConfig | This setting will affect which type of indicator you use and config contains a lot props,such as triigerDistance,completedurtion... | Config | LoadConfig | optional |
| enableOverScroll | the switch of Overscroll,When you use RefreshIndicator(Material), you may have to shut down. | bool | true | optional |
Expand All @@ -127,9 +144,10 @@ RefreshConfig:

| Attribute Name | Attribute Explain | Default Value |
|---------|--------------------------|:-----:|
| height | Height used to provide a cover indicator | 50.0 |
| triggerDistance | Drag distance to trigger refresh | 100.0 |
| completeDuration | Stay in time when you return to success and failure | 800 |
| visibleRange | The scope of the indicator can be seen(refresh state) | 50.0 |


LoadConfig:

Expand All @@ -140,6 +158,13 @@ LoadConfig:
| bottomWhenBuild | Is it at the bottom of listView when it is loaded(When your header is LoadConfig) | true |

## FAQ
* <h3>When the amount of data is too small, how to hide the pull-up component?</h3>
Flutter doesn't seem to provide Api so that we can get the total height of all items in ListView, so I don't have a way to hide automatically according to the height. This requires you to take the initiative to determine whether it is necessary to hide.
Assuming you need to hide the pull-up control, you can set enablePullUp to false to hide it and not trigger callbacks for the pull-up. Example in[example4](https://github.com/peng8350/flutter_pulltorefresh/blob/master/example/lib/ui/Example1.dart)

* <h3>SliverAppBar,CustomScrollView Conflict Incompatibility?</h3>
CustomScrollView is used inside my control, which has not been solved for the time being.

* <h3>Does it support simple RefreshIndicator (material) + pull up loading and no elastic refresh combination?<br></h3>
Yes, as long as you set the node properties enableOverScroll = false, enablePullDown = false, it's OK to wrap a single RefreshIndicator outside, and
[Example4](https://github.com/peng8350/flutter_pulltorefresh/blob/master/example/lib/ui/Example3.dart) has given an example in demo.
Expand Down
58 changes: 49 additions & 9 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,28 @@
```
dependencies:
pull_to_refresh: ^1.1.6
pull_to_refresh: ^1.2.0
```

2.然后,导入,SmartRefresher是一个组件包装在你的外部,child就是你的内容控件
2.然后,导入,SmartRefresher是一个组件包装在你的外部,child就是你的内容控件,并且需要构建RefreshController

```
import "package:pull_to_refresh/pull_to_refresh.dart";
....
void initState(){
_refreshController = new RefreshController();
......
}
build() =>
new SmartRefresher(
controller:_refreshController,
enablePullDown: true,
enablePullUp: true,
onRefresh: _onRefresh,
Expand All @@ -57,13 +64,17 @@

3.你应该要根据不同的刷新模式状态下,显示不同的布局.当然,
我这里已经构造了一个指示器方便使用,叫做ClassicIndicator,
如果不符合要求,也可以选择自己定义一个指示器
如果不符合要求,也可以选择自己定义一个指示器。同时也可以设置headerConfig,footerConfig。
注意:这里的RefreshConfig高度一定要和对应的指示器布局高度完全一致。(主要是内部要获取指示器高度,避免二次渲染)

```
Widget _buildHeader(context,mode){
return new ClassicIndicator(mode: mode);
return new Container(
height:50.0,
child:new ClassicIndicator(mode: mode)
);
}
Expand All @@ -75,7 +86,10 @@
new SmartRefresher(
....
footerBuilder: _buildFooter,
headerBuilder: _buildHeader
headerBuilder: _buildHeader,
//假如是RefreshConfig,height一定要和buildHeader返回的部件高度完全一致
headerConfig:const RefreshConfig(height:50.0),
footerConfig:const LoadConfig()
)
Expand All @@ -85,16 +99,31 @@
4.
无论是顶部还是底部指示器,onRefresh都会被回调当这个指示器状态进入刷新状态。
但我要怎么把结果告诉SmartRefresher,这不难。内部提供一个Controller,通过contrleer.
sendBack(int status)就可以告诉它返回什么状态
sendBack就可以告诉它返回什么状态

```
void _onRefresh(bool up){
if(up){
//headerIndicator callback
new Future.delayed(const Duration(milliseconds: 2009))
.then((val) {
/* 注意:假如headerConfig的autoLoad开启了,就不得不等到下一针被重绘时才更新状态,不然会出现多次刷新的情况
SchedulerBinding.instance.addPostFrameCallback(
(_){
_refreshController.sendBack(true, RefreshStatus.completed);
}
);
*/
_refreshController.sendBack(true, RefreshStatus.completed);
});
new Future.delayed(const Duration(milliseconds: 2009))
.then((val) {
_refreshController.sendBack(true, RefreshStatus.failed);
_refreshController.sendBack(true, RefreshStatus.completed);
});
}
Expand All @@ -113,13 +142,13 @@ SmartRefresher:
| Attribute Name | Attribute Explain | Parameter Type | Default Value | requirement |
|---------|--------------------------|:-----:|:-----:|:-----:|
| child | 你的内容部件 | ? extends ScrollView | null | 必要
| controller | 控制内部状态 | RefreshController | null | 必要 |
| headerBuilder | 头部指示器构造 | (BuildContext,RefreshMode) => Widget | null | 如果你打开了下拉是必要,否则可选 |
| footerBuilder | 尾部指示器构造 | (BuildContext,RefreshMode) => Widget | null | 如果你打开了上拉是必要,否则可选 |
| enablePullDown | 是否允许下拉 | boolean | true | 可选 |
| enablePullUp | 是否允许上拉 | boolean | false | 可选 |
| onRefresh | 进入刷新时的回调 | (bool) => Void | null | 可选 |
| onOffsetChange | 它将在超出边缘范围拖动时回调 | (double) => Void | null | 可选 |
| controller | 控制内部状态 | RefreshController | null | optional |
| headerConfig | 这个设置会影响你使用哪种指示器,config还有几个属性可以设置 | Config | RefreshConfig | optional |
| footerConfig | 这个设置会影响你使用哪种指示器,config还有几个属性可以设置 | Config | LoadConfig | optional |
| enableOverScroll | 越界回弹的开关,如果你要配合RefreshIndicator(material包)使用,有可能要关闭 | bool | true | optional |
Expand All @@ -128,9 +157,10 @@ RefreshConfig:

| Attribute Name | Attribute Explain | Default Value |
|---------|--------------------------|:-----:|
| height | 用于提供一个遮盖指示器的高度 | 50.0 |
| triggerDistance | 触发刷新的距离 | 100.0 |
| completeDuration | 返回成功和失败时的停留时间 | 800 |
| visibleRange | 指示器的可见范围(刷新状态) | 50.0 |


LoadConfig:

Expand All @@ -141,6 +171,16 @@ LoadConfig:
| bottomWhenBuild | 是否加载时处于listView最底部(当你的header是LoadConfig) | true |

## FAQ
* <h3>当数据量太小的时候,如何去隐藏上拉加载组件?</h3>
flutter好像没有提供Api让我们可以获得ListView里的所有item加起来的高度,所以我内部并没有提供方法去根据高度自动隐藏的功能。这就需要你自己去主动判断是否有必要去隐藏。
假设你需要隐藏上拉加载控件,你可以给enablePullUp设置为false即可隐藏掉它,也不会触发上拉加载的回调。例子在[example4](https://github.com/peng8350/flutter_pulltorefresh/blob/master/example/lib/ui/Example1.dart)

* <h3>关于SliverAppBar,和CustomScrollView一起使用冲突问题</h3>
我控件内部采用的是CustomScrollView,这个问题暂时没有得到好的解决办法。

* <h3>是否支持反转?</h3>
这个问题相对来说有点麻烦,暂时不支持。

* <h3>是否支持单纯RefreshIndicator(material)+上拉加载并且没有弹性的刷新组合?</h3>
可以,只要设置节点属性enableOverScroll = false, enablePullDown = false,在外面包裹一个是否支持
单纯RefreshIndicator就可以了,demo里
Expand Down
1 change: 0 additions & 1 deletion example/lib/ui/Example1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Example1State extends State<Example1> {

@override
Widget build(BuildContext context) {
_scrollController = new ScrollController();
return new LayoutBuilder(builder: (BuildContext c,BoxConstraints bc){
double innerListHeight= data.length*100.0;
double listHeight = bc.biggest.height;
Expand Down
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.1.6
version: 1.2.0
author: Jpeng <peng8350@gmail.com>
homepage: https://github.com/peng8350/flutter_pulltorefresh

Expand Down

0 comments on commit 5babb20

Please sign in to comment.