Skip to content

Commit 36a898f

Browse files
author
Kamil Klyta
committed
Update readme.md
1 parent 6bab507 commit 36a898f

14 files changed

+145
-87
lines changed

CHANGELOG.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
1-
## [1.0.0]
1+
## [0.8.0] - April 12, 2020
2+
23
## BREAKING API CHANGES
3-
* Feedback improvements (thank you for emails!):
4-
* Changed long identifier names:
5-
* `CustomRefreshIndicatorData` => `IndicatorData`
6-
* `CustomRefreshIndicatorState` => `IndicatorState`
7-
* `CustomIndicatorBuilder` => `IndicatorBuilder`
8-
* Changed `indicatorState` key contained in `IndicatorData` to => `state`
9-
* ## `indicatorBuilder` function is no longer called on every `IndicatorData` change!
10-
11-
To animate indicator based on `IndicatorData` you can use `AnimationBuilder` widget and pass `IndicatorData` object as `animation` argument. Because of that you can implement your own widget rebuild system what can improve your custom indicator performance (instead of building indicator eg. 300 times you can decide when you want to do it). Example:
4+
5+
- Feedback improvements (thank you for your emails!):
6+
- Changed long identifier names:
7+
- `CustomRefreshIndicatorData` => `IndicatorController`
8+
- `CustomRefreshIndicatorState` => `IndicatorState`
9+
- Update example app
10+
- ## `indicatorBuilder` argument is no longer present. Instead use `builder` argument which has some significant changes.
11+
12+
To animate indicator based on `IndicatorControler` you can use `AnimationBuilder` widget and pass `IndicatorData` object as `animation` argument. Because of that you can implement your own widget rebuild system what can improve your custom indicator performance (instead of building indicator eg. 300 times you can decide when you want to do it). Example:
13+
1214
```dart
1315
return CustomRefreshIndicator(
1416
child: ListView(children: <Widget>[/* ... */]),
15-
indicatorBuilder: (BuildContext context, IndicatorData data) {
17+
builder: (
18+
BuildContext context,
19+
/// Subtree that contains scrollable widget and was passed
20+
/// to child argument
21+
Widget child,
22+
/// Now all your data will be stored in controller.
23+
/// To get controller outside of this function
24+
/// 1. Create controller in parent widget and pass it to CustomRefreshIndicator
25+
/// 2. Assign [GlobalKey] to CustomRefreshIndicator and access `key.currentState.controller`.
26+
IndicatorController controller
27+
) {
1628
return AnimatedBuilder(
1729
// IndicatorData extends ChangeNotifier class so it is possible to
18-
// assign it to an AnimationBuilder and take advantage of subtree rebuild
19-
animation: data,
30+
// assign it to an AnimationBuilder widget and take advantage of subtree rebuild
31+
animation: controller,
2032
child: MyPrebuildWidget(),
33+
child: child,
2134
builder: (BuildContext context, Widget child) {
22-
return MyCustomIndicator(child: child);
35+
/// TODO: Implement your custom refresh indicator
2336
},
2437
);
2538
},
2639
onRefresh: myAsyncMethod,
2740
);
2841
```
42+
2943
## [0.2.1]
30-
* Upgrade example to AndroidX
31-
* Improved README
44+
45+
- Upgrade example to AndroidX
46+
- Improved README
47+
3248
## [0.2.0] - Added support for BouncingScrollPhysics.
33-
* Added support for `BouncingScrollPhysics` - ios default sroll physics
34-
* Improved readme
49+
50+
- Added support for `BouncingScrollPhysics` - ios default sroll physics
51+
- Improved readme
52+
3553
## [0.1.1]
36-
* Extracted inbox example to [`letter_refresh_indicator`](https://pub.dev/packages/letter_refresh_indicator) package
37-
## [0.1.0] - Initial version.
38-
* Added basic `CustomRefreshIndicator` widget with `CustomRefreshIndicatorData` class.
39-
* Added `SimpleIndicatorContainer` widget which simulate default `RefreshIndicator` container
40-
* Added examples:
41-
* inbox
42-
* simple
43-
* blur
4454

55+
- Extracted inbox example to [`letter_refresh_indicator`](https://pub.dev/packages/letter_refresh_indicator) package
4556

57+
## [0.1.0] - Initial version.
4658

59+
- Added basic `CustomRefreshIndicator` widget with `CustomRefreshIndicatorData` class.
60+
- Added `SimpleIndicatorContainer` widget which simulate default `RefreshIndicator` container
61+
- Added examples:
62+
- inbox
63+
- simple
64+
- blur

README.md

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,137 @@
11
# Flutter Custom Refresh Indicator
22

3-
This package provides `CustomRefreshIndicator` widget that make it easy to implement your own custom refresh indicator.
3+
This package provides `CustomRefreshIndicator` widget that make it easy to implement your own custom refresh indicator. It listens for scroll events from scroll widget passed to child argument and parsing it to data easy for custom refresh indicator implementation. Indicator data is provided by IndicatorController (third argument of builder method). Long story short... thats it!
4+
5+
If there is something that can be improved, fixed or you just have some great idea feel free to open github issue [HERE](https://github.com/gonuit/flutter-custom-refresh-indicator/issues) or open a pull request [HERE](https://github.com/gonuit/flutter-custom-refresh-indicator/pulls).
6+
7+
If you implemented your own custom refresh indicator with this library and you want it to be mentioned here or provided as an example to the eample app, just open a pull request [HERE](https://github.com/gonuit/flutter-custom-refresh-indicator/pulls).
8+
9+
## QUICK START
10+
11+
### Code
412

5-
## Usage
613
```dart
714
CustomRefreshIndicator(
8-
// Your custom indicator builder
9-
indicatorBuilder: (context, data) => SimpleIndicatorContainer(
10-
data: data,
11-
child: SimpleIndicatorContent(data: data),
12-
),
13-
onRefresh: myAsyncRefreshMethod,
14-
// Your child scroll widget
15+
/// Scrollable widget
1516
child: ListView.separated(
1617
itemBuilder: (BuildContext context, int index) => const SizedBox(
1718
height: 100,
1819
),
1920
separatorBuilder: (BuildContext context, int index) =>
2021
const SizedBox(height: 20),
2122
),
23+
/// Custom indicator builder function
24+
builder: (
25+
BuildContext context,
26+
Widget child,
27+
IndicatorController controller,
28+
) {
29+
/// TODO: Implement your own refresh indicator
30+
return Stack(
31+
children: <Widget>[
32+
AnimatedBuilder(
33+
animation: controller,
34+
builder: (BuildContext context, _) {
35+
/// This part will be rebuild on every controller change
36+
return MyIndicator();
37+
},
38+
),
39+
/// Scrollable widget that was provided as [child] argument
40+
///
41+
/// TIP:
42+
/// You can also wrap [child] with [Transform] widget to also a animate list transform (see example app)
43+
child,
44+
],
45+
);
46+
}
47+
/// A function that's called when the user has dragged the refresh indicator
48+
/// far enough to demonstrate that they want the app to refresh.
49+
/// Should return [Future].
50+
onRefresh: myAsyncRefreshMethod,
2251
)
2352
```
2453

25-
## Getting started
54+
### How the controller data change
55+
56+
The best way to understand how the "CustomRefreshIndicator" widget changes its controller data is to see the example 😉.
57+
![Controller_Data](readme/controller_data.gif)
2658

2759
## Examples
28-
### Use of `SimpleIndicatorContainer` with `Icon` as child [LINK](example/lib/indicators/simple_indicator.dart)
29-
![simple_indicator](readme/simple_container.gif)
3060

31-
### Envelope indicator
32-
![letter_indicator](readme/letter_indicator.gif)
61+
Almost all of these examples are available in the example application.
3362

63+
### Plane indicator [[SOURCE CODE](example/lib/indicators/plane_indicator.dart)]
3464

65+
![plane_indicator](readme/plane_indicator.gif)
3566

36-
### `CustomRefreshIndicator`
37-
`CustomRefreshIndicator` has an absolute minimum functionality that allows you to create and set your own custom indicators.
67+
### Ice cream indicator [[SOURCE CODE](example/lib/indicators/ice_cream_indicator.dart)]
3868

39-
#### Arguments
40-
| Argument | Type | Default value | Required |
41-
| :---------------------------------- | :-------------------------------------------------------------- | :----------------------------- | :---------------- |
42-
| child | `Widget` | none | true |
43-
| onRefresh | `Future<void> Function()` | none | true |
44-
| indicatorBuilder | `Widget Function(BuildContext, CustomRefreshIndicatorData) ` | none | true |
45-
| dragingToIdleDuration | `Duration` | `Duration(milliseconds: 300)` | false |
46-
| armedToLoadingDuration | `Duration` | `Duration(milliseconds: 200)` | false |
47-
| loadingToIdleDuration      | `Duration` | `Duration(milliseconds: 100)` | false |
48-
| leadingGlowVisible          | `bool` | `false` | false |
49-
| trailingGlowVisible          | `bool` | `true` | false |
69+
![ice_cream_indicator](readme/ice_cream_indicator.gif)
5070

71+
### Simple indicator made with `PositionedIndicatorContainer` [[SOURCE CODE](example/lib/indicators/simple_indicator.dart)]
5172

52-
### `CustomRefreshIndicatorData`
53-
Contains data provided by `CustomRefreshIndicator` that could be usefull for your custom indicator implementation.
73+
![simple_indicator](readme/simple_with_opacity.gif)
5474

55-
### Arguments
75+
### Envelope indicator
76+
77+
![letter_indicator](readme/letter_indicator.gif)
78+
79+
### Emoji indicator [[SOURCE CODE](example/lib/indicators/emoji_indicator.dart)]
80+
81+
You can create any indicator you want!
5682

57-
| argument | type |
58-
| :----------------- | :---------------------------- |
59-
| value | `double` |
60-
| direction | `AxisDirection` |
61-
| scrollingDirection | `ScrollDirection` |
62-
| indicatorState | `IndicatorState` |
83+
![letter_indicator](readme/emoji_indicator.gif)
6384

64-
#### value
85+
## CustomRefreshIndicator widget
6586

66-
### `IndicatorState`
67-
Enum which describes state of CustomRefreshIndicator.
87+
`CustomRefreshIndicator` widget provides an absolute minimum functionality that allows you to create and set your own custom indicators.
88+
89+
## IndicatorState
90+
91+
Enum which describes state of CustomRefreshIndicator. It is provided by IndicatorController.
6892

6993
#### `idle`
70-
`CustomRefreshIndicator` is idle (There is no action)
71-
72-
(`CustomRefreshIndicatorData.value == 0`)
94+
95+
CustomRefreshIndicator is idle (There is no action)
96+
97+
```dart
98+
controller.value == 0.0
99+
```
73100

74101
#### `draging`
75-
Whether user is draging `CustomRefreshIndicator` ending the scroll **WILL NOT** result in `onRefresh` call
76-
77-
(`CustomRefreshIndicatorData.value < 1`)
102+
103+
Whether the user is dragging a scrollable widget.
104+
Ending the scroll **WILL NOT** result in `onRefresh` function call
105+
106+
```dart
107+
controller.value < 1.0
108+
```
78109

79110
#### `armed`
80-
`CustomRefreshIndicator` is armed ending the scroll **WILL** result in:
81-
- `CustomRefreshIndicator.onRefresh` call
82-
- change of status to `loading`
83-
- decreasing `CustomRefreshIndicatorData.value` to `1` in duration specified by `CustomRefreshIndicator.armedToLoadingDuration`)
84-
85-
(`CustomRefreshIndicatorData.value >= 1`)
111+
112+
CustomRefreshIndicator is armed ending the scroll **WILL** result in:
113+
114+
- `onRefresh` function call
115+
- change of indicator status to `loading`
116+
- decreasing controller.value to `1.0` in duration specified by `armedToLoadingDuration` CustomRefreshIndicator widget argument
117+
118+
```dart
119+
controller.value >= 1.0
120+
```
86121

87122
#### `hiding`
88-
CustomRefreshIndicator is hiding indicator when `onRefresh` future is resolved or indicator was canceled (scroll ended when [IndicatorState] was equal to `dragging` so `value` was less than `1` or the user started scrolling through the list)
89-
90-
(`CustomRefreshIndicatorData.value` decreases to `0` in duration specified by `CustomRefreshIndicator.dragingToIdleDuration`)
123+
124+
CustomRefreshIndicator is hiding its indicator. After the future returned from `onRefresh` function is completed or scroll ended when the state was equal to `dragging` or the user started scrolling through the list.
125+
controller value decreases to `0.0` in duration specified by `dragingToIdleDuration` CustomRefreshIndicator widget argument.
126+
127+
```dart
128+
controller.value <= 1.0
129+
```
91130

92131
#### `loading`
93-
`CustomRefreshIndicator` is awaiting on `onRefresh` call result. When `onRefresh` will resolve `CustomRefreshIndicator` will change state from `loading` to `hiding` and decrease `CustomRefreshIndicatorData.value` from `1` to `0` in duration specified by `CustomRefreshIndicator.loadingToIdleDuration`
94-
95-
(`CustomRefreshIndicatorData.value == 1`)
132+
133+
CustomRefreshIndicator widget is awaiting on future returned from `onRefresh` function. After future completed state will be change into `hiding` and controller value will decrease from `1.0` to `0.0` in duration specified by `loadingToIdleDuration` CustomRefreshIndicator widget argument.
134+
135+
```dart
136+
controller.value == 1.0
137+
```

example/lib/indicators/plane_indicator.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class _Cloud {
3030
});
3131
}
3232

33-
/// Desgin by Katarzyna Klyta kasia@klyta.it
3433
class PlaneIndicator extends StatefulWidget {
3534
final Widget child;
3635
const PlaneIndicator({

example/lib/screens/presentation_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
2-
import 'package:example/indicators/custom_indicator.dart';
32
import 'package:example/widgets/example_app_bar.dart';
43
import 'package:flutter/material.dart';
54

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ packages:
7777
path: ".."
7878
relative: true
7979
source: path
80-
version: "0.2.1"
80+
version: "0.8.0"
8181
flutter:
8282
dependency: "direct main"
8383
description: flutter

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: custom_refresh_indicator
22
description: Flutter Widget that make it easy to implement custom refresh indicator.
3-
version: 0.2.1
3+
version: 0.8.0
44
repository: https://github.com/gonuit/flutter-custom-refresh-indicator
55
issue_tracker: https://github.com/gonuit/flutter-custom-refresh-indicator/issues
66
homepage: https://github.com/gonuit/flutter-custom-refresh-indicator

readme/blur_indicator.gif

-1.46 MB
Binary file not shown.

readme/controller_data.gif

5.43 MB
Loading

readme/crazy.gif

-1.91 MB
Binary file not shown.

readme/emoji_indicator.gif

3.09 MB
Loading

0 commit comments

Comments
 (0)