Skip to content

Commit bb5bc5b

Browse files
committed
Update didStateChange method section in readme file
1 parent eb202c8 commit bb5bc5b

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
2-
## 1.0.0-nullsafety.1
1+
## 1.0.0
32
- Stable nullsafety release.
3+
- **BREAKING**: opt into null safety
4+
- Dart SDK constraints: >=2.12.0-0 <3.0.0
45
- **BREAKING**: Removed `prevState` from `IndicatorController` class.
56
Because flutter only marks the widget that it is ready for rebuild, it is possible that the controller state will change more than once during a single frame what causes one or more steps to be skipped. To still use `prevState` and `didChangeState` method, you can use `IndicatorStateHelper`. Take a look at `check_mark_indicator.dart` or `warp_indicator.dart` for example usage.
67
- Added `IndicatorStateHelper` class.
78
- Added `IndicatorController` unit tests.
89
- Added warp indicator example.
9-
10-
## 1.0.0-nullsafety.0
11-
12-
- **BREAKING**: opt into null safety
13-
- Dart SDK constraints: >=2.12.0-0 <3.0.0
10+
- Added `stopDrag` method to the `IndicatorController` class. It allows you to stop current user drag.
1411

1512
## 0.9.0
1613

README.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ If there is something that can be improved, fixed or you just have some great id
99
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).
1010

1111
### Table of Contents
12+
1213
- [Flutter Custom Refresh Indicator](#flutter-custom-refresh-indicator)
13-
- [Table of Contents](#table-of-contents)
14+
- [Table of Contents](#table-of-contents)
1415
- [QUICK START](#quick-start)
1516
- [Examples](#examples)
1617
- [Documentation](#documentation)
@@ -72,15 +73,12 @@ Almost all of these examples are available in the example application.
7273

7374
| Warp indicator [[SOURCE CODE](example/lib/indicators/warp_indicator.dart)] | Envelope indicator |
7475
| :------------------------------------------------------------------------: | :----------------------------------------------: |
75-
| ![warp_indicator](readme/warp_indicator.gif) | ![letter_indicator](readme/letter_indicator.gif) |
76+
| ![warp_indicator](readme/warp_indicator.gif) | ![letter_indicator](readme/letter_indicator.gif) |
7677

7778
| Indicator with complete state [[SOURCE CODE](example/lib/indicators/check_mark_indicator.dart)] | Your indicator |
7879
| :---------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
7980
| ![indicator_with_complete_state](readme/indicator_with_complete_state.gif) | Have you created a fancy refresh indicator? This place is for you. Open PR. |
8081

81-
82-
83-
8482
# Documentation
8583

8684
## CustomRefreshIndicator widget
@@ -92,7 +90,7 @@ Almost all of these examples are available in the example application.
9290
### Controller state and value changes.
9391

9492
The best way to understand how the "CustomRefreshIndicator" widget changes its controller data is to see the example 😉. An example is available in the example application.
95-
93+
9694
![Controller_Data](readme/controller_data.gif)
9795

9896
| state | value | value description | Description |
@@ -104,34 +102,52 @@ The best way to understand how the "CustomRefreshIndicator" widget changes its c
104102
| **hiding** | `<=1.0` | Value decreses in duration of `draggingToIdleDuration` or `loadingToIdleDuration` arguments to `0.0`. | Indicator is hiding after:<br />- User ended dragging when indicator was in `dragging` state.<br />- Future returned from `onRefresh` function is resolved.<br />- Complete state ended.<br />- User started scrolling through the list. |
105103
| **complete** | `==1.0` | Value equals `1.0` for duration of `completeStateDuration` argument. | **This state is OPTIONAL, provide `completeStateDuration` argument with non null value to enable it.**<br /> Loading is completed. |
106104

107-
___
105+
---
108106

109-
### `didStateChange`
110-
With this method, you can easily check if the indicator's state has changed.
107+
### IndicatorStateHelper
111108

109+
With the IndicatorStateHelper class, you can easily track indicator's state changes. Example usage can be found [HERE](example/lib/indicators/check_mark_indicator.dart).
110+
111+
All you need to do is to update it's value on every controller update.
112+
```dart
113+
CustomRefreshIndicator(
114+
onRefresh: onRefresh,
115+
child: widget.child,
116+
builder: (
117+
BuildContext context,
118+
Widget child,
119+
IndicatorController controller,
120+
) => AnimatedBuilder(
121+
animation: controller,
122+
builder: (BuildContext context, Widget? _) {
123+
/// Now every state change will be tracked by the helper class.
124+
_helper.update(controller.state);
125+
// ...
126+
```
127+
Then you can simply track state changes:
112128
```dart
113129
/// When the state changes to [idle]
114-
if(controller.didStateChange(to: IndicatorState.idle)) {
130+
if(_helper.didStateChange(to: IndicatorState.idle)) {
115131
// Code...
116132
}
117133
118134
/// When the state changes from [idle] to [dragging]
119-
if (controller.didStateChange(
135+
if (_helper.didStateChange(
120136
from: IndicatorState.idle,
121137
to: IndicatorState.dragging,
122138
)) {
123139
// Code...
124140
}
125141
126142
/// When the state changes from [idle] to another.
127-
if (controller.didStateChange(
143+
if (_helper.didStateChange(
128144
from: IndicatorState.idle,
129145
)) {
130146
// Code...
131147
}
132148
133149
/// When the state changes.
134-
if (controller.didStateChange()) {
150+
if (_helper.didStateChange()) {
135151
// Code...
136152
}
137-
```
153+
```

0 commit comments

Comments
 (0)