Skip to content

Commit

Permalink
Release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peng8350 committed May 6, 2019
1 parent e486458 commit fec5bb0
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 285 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,27 @@ Notice: This version of the code changes much, Api too
* 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
* change RefreshStatus from int to enum

## 1.3.0
### Total
* Support reverse ScrollView
* Remove RefreshConfig,LoadConfig,Move to indicator setting
* Add isNestWrapped to Compatible NestedScrollView
* replace headerBuilder,footerBuilder attribute to header,footer
* Separate header and footer operations:onRefresh and onLoading Callback,RefreshStatus is separated into RefreshStatus.LoadStatus
* Fix Bug: twice loading (the footer state change before the ui update)
*

### RefreshController
* Remove sendBack method,replaced by LoadComplete,RefreshComplete ,RefreshFailed,LoadNoData
* Separate refresh and load operations
* Add dispose method for Safety in some situation

### Indicator
* Use another way to achieve drop-down refresh
* Add drop-down refresh indicator style(Follow,UnFollow,Behind)
* Add WaterDropIndicator,CustomIndicator
* Make Custom Indicator easily


180 changes: 57 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,118 +10,80 @@ If you are Chinese,click here([中文文档](https://github.com/peng8350/flutter
* It's almost fit for all witgets,like GridView,ListView,Container...
* High extensibility,High degree of freedom
* powerful Bouncing
* support reverse ScrollView
* provide more refreshStyle: Behind,Follow,UnFollow

## Screenshots
![](arts/screen1.gif)
![](arts/screen2.gif)<br>

## 指示器截图

|Style|Classic Follow| Classic UnFollow |
|:---:|:---:|:---:|
|art|![](example/images/classical_follow.gif)|![](example/images/classical_unfollow.gif))|

|Style| Behind | WaterDrop(QQ)|
|:---:|:---:|:---:|
|art|![](arts/screen1.gif)|![](example/images/warterdrop.gif))|

## How to use?
1.the first declare following in your pubspec.yml

```

dependencies:
pull_to_refresh: ^1.2.0
```

2.and then,import that line,SmartRefresher is a component that is wrapped outside your content View
## How to use?

```
import "package:pull_to_refresh/pull_to_refresh.dart";
....
build() =>
new SmartRefresher(
controller:_refreshController,
enablePullDown: true,
enablePullUp: true,
onRefresh: _onRefresh,
onOffsetChange: _onOffsetCallback,
child: new ListView.builder(
itemExtent: 40.0,
itemCount: data.length,
itemBuilder: (context,index){
return data[index];
},
)
)
dependencies:
pull_to_refresh: ^1.3.0
```

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 Container(
height:50.0,
child:new ClassicIndicator(mode: mode)
);
}
Widget _buildFooter(context,mode){
// the same with header
....
}
new SmartRefresher(
....
footerBuilder: _buildFooter,
headerBuilder: _buildHeader,
// must be exactly the same as the component returned by buildHeader
headerConfig:const RefreshConfig(height:50.0),
footerConfig:const LoadConfig()
)


```
4.
Whether at the top or bottom, the onRefresh will be callback when the indicator state is refreshed.
But how can I tell the result to SmartRefresher? It's very simple. It provides a RefreshController inside, you can pass the construction of a controller to SmartRefresher, and then call.SendBack (int status) can change the state of success or failure.
RefreshController _refreshController;
initState(){
super.initState();
_refreshController = RefreshController();
}
void _onRefresh(){
/*. after the data return,
use _refreshController.refreshComplete() or refreshFailed() to end refreshing
*/
}
void _onLoading(){
/*
use _refreshController.loadComplete() or loadNoData() to end loading
*/
}
build(){
...
SmartRefresher(
enablePullDown: true,
enablePullUp: true,
header: WaterDropHeader(),
controller: _refreshController,
onRefresh: _onRefresh,
onLoading: _onLoading,
child: "yourContentScrollView",
)
....
}
```
// don't forget to dispose refreshController
void dispose(){
_refreshController.dispose();
super.dispose();
}
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);
});
}
else{
//footerIndicator Callback
}
}
```

5.When the amount of data is too small, there is no automatic judgment to hide. You need to dynamically judge the height and actual size of listView. The height of listView can be determined by LayoutBuilder
When the amount of data is too small, there is no automatic judgment to hide. You need to dynamically judge the height and actual size of listView. The height of listView can be determined by LayoutBuilder
,[example1](https://github.com/peng8350/flutter_pulltorefresh/blob/master/example/lib/ui/Example1.dart) is an example.

```
Expand All @@ -147,59 +109,31 @@ SmartRefresher:
|---------|--------------------------|:-----:|:-----:|:-----:|
| 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 |
| header | the header indictor | RefreshIndicator | ClassicHeader |if optional |
| footer | the footer indictor | LoadIndicator | optional |
| 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 |
| onRefresh | will callback when the header indicator is getting refreshing | (bool) => Void | null | optional |
| onLoad | will callback when the footer indicator is getting loading | (bool) => Void | null | optional |
| onOffsetChange | callback while you dragging and outOfrange | (bool,double) => Void | 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 |
| isNestWrapped | it will set true when SmartRefresher is wrapped by NestedScrollView | bool | false | optional |

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 |


LoadConfig:

| Attribute Name | Attribute Explain | Default Value |
|---------|--------------------------|:-----:|
| triggerDistance | Drag distance to trigger loading | 5.0 |
| autoLoad | enable open Auto Load,If false triggerDistance is invalid | true |
| bottomWhenBuild | Is it at the bottom of listView when it is loaded(When your header is LoadConfig) | true |

## FAQ
* <h3>Is it possible to automatically determine that the amount of data is larger than one page and hide the pull-up component?</h3>
There's no good way to do that right now. Flutter doesn't seem to provide Api so that we can get the total height of all items in ListView (before the interface is rendered). If anyone can solve this problem, please put it forward. Thank you very much.

* <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.

* <h3>Does it support an indicator that does not follow the list?<br></h3>
This I did not package in the library, because even if I encapsulated,
it would only make the logic complexity of the code increased,
so you need yourself to use the onOffsetChange callback method to implement it.
It is not difficult to use Stack to encapsulate it. It can refer to the idea of
[Example3](https://github.com/peng8350/flutter_pulltorefresh/blob/master/example/lib/ui/Example3.dart) or my project [flutter_gank](https://github.com/peng8350/flutter_gank).

* <h3>Why does child attribute extend from original widget to scrollView?<br></h3>
Because of my negligence, I didn't take into account the problem that child needed to cache the item,
so the 1.1.3 version had corrected the problem of not caching.

* <h3>What impact does this library have on performance?<br></h3>
No, although I did not actually use data to test performance problems,
I did not appear to pull up or pull down the sliding carton situation in
the process of another project development.

* <h3>Is there any way to achieve the maximum distance to limit springback?<br></h3>
The answer is negative. I know that it must be done by modifying the ScrollPhysics,
Expand Down
Loading

0 comments on commit fec5bb0

Please sign in to comment.