Skip to content

Commit c3cf8d6

Browse files
author
Kamil Klyta
committed
Add descriptions to custom refresh indicator widget
1 parent 91e5f4d commit c3cf8d6

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

example/lib/indicators/custom_indicator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
22
import 'package:flutter/foundation.dart';
33

44
class CustomIndicatorConfig {
5-
final ChildTransformBuilder builder;
5+
final IndicatorBuilder builder;
66

77
const CustomIndicatorConfig({
88
@required this.builder,

lib/custom_refresh_indicator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
library custom_refresh_indicator;
22

3+
import 'package:flutter/material.dart';
34
import 'package:flutter/rendering.dart';
45
import 'package:flutter/widgets.dart';
56

67
part 'src/helpers/positioned_indicator_container.dart';
78
part 'src/custom_refresh_indicator.dart';
8-
part 'src/definitions.dart';
9+
part 'src/controller.dart';

lib/src/definitions.dart renamed to lib/src/controller.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
part of custom_refresh_indicator;
22

3-
typedef ChildTransformBuilder = Widget Function(
4-
BuildContext context,
5-
Widget child,
6-
IndicatorController controller,
7-
);
8-
93
/// Describes state of CustomRefreshIndicator
104
enum IndicatorState {
115
/// #### [CustomRefreshIndicator] is idle (There is no action)
@@ -146,7 +140,7 @@ class IndicatorController extends ChangeNotifier {
146140
bool _refreshEnabled;
147141

148142
/// Whether custom refresh indicator can change [IndicatorState] from `idle` to `draging`
149-
bool get refreshEnabled => _refreshEnabled;
143+
bool get isRefreshEnabled => _refreshEnabled;
150144

151145
/// Disables list pull to refresh
152146
void disableRefresh() {

lib/src/custom_refresh_indicator.dart

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
11
part of custom_refresh_indicator;
22

3-
typedef RefreshCallback = Future<void> Function();
3+
typedef IndicatorBuilder = Widget Function(
4+
BuildContext context,
5+
Widget child,
6+
IndicatorController controller,
7+
);
48

59
class CustomRefreshIndicator extends StatefulWidget {
610
static const armedFromValue = 1.0;
7-
static const defaultExtentPercentageToArmed = 0.3;
11+
static const defaultExtentPercentageToArmed = 0.20;
812

13+
/// Duration of changing [IndicatorController] value from `<1.0` to `0.0`.
14+
/// When user stop dragging list before it become to armed [IndicatorState].
915
final Duration dragingToIdleDuration;
16+
17+
/// Duration of changing [IndicatorController] value from `<=1.5` to `1.0`.
18+
/// Will start just before [onRefresh] function invocation.
1019
final Duration armedToLoadingDuration;
20+
21+
/// Duration of changing [IndicatorController] value from `1.0` to `0.0`
22+
/// when [onRefresh] callback was completed.
1123
final Duration loadingToIdleDuration;
24+
25+
/// Whether to display leading glow
1226
final bool leadingGlowVisible;
27+
28+
/// Whether to display trailing glow
1329
final bool trailingGlowVisible;
30+
31+
/// Number of pixels that user should drag to change [IndicatorState] from idle to armed.
1432
final double offsetToArmed;
33+
34+
/// Value from 0.0 to 1.0 that describes the percentage of scroll container extent
35+
/// that user should drag to change [IndicatorState] from idle to armed.
1536
final double extentPercentageToArmed;
37+
38+
/// Part of widget tree that contains scrollable element (like ListView).
39+
/// Scroll notifications from the first scrollable element will be used
40+
/// to calculate [IndicatorController] data.
1641
final Widget child;
17-
final ChildTransformBuilder builder;
42+
43+
/// Function in wich custom refresh indicator should be implemented.
44+
///
45+
/// IMPORTANT:
46+
/// IT IS NOT CALLED ON EVERY [IndicatorController] DATA CHANGE.
47+
///
48+
/// TIP:
49+
/// To rebuild widget on every [IndicatorController] data change, consider
50+
/// using [IndicatorController] that is passed to this function as the third argument
51+
/// in combination with [AnimationBuilder].
52+
final IndicatorBuilder builder;
53+
54+
/// A function that's called when the user has dragged the refresh indicator
55+
/// far enough to demonstrate that they want the app to refresh.
56+
/// The returned [Future] must complete when the refresh operation is finished.
1857
final RefreshCallback onRefresh;
58+
59+
/// Indicator controller keeps all thata related to refresh indicator.
60+
/// It extends [ChangeNotifier] so that it could be listen for changes.
61+
///
62+
/// TIP:
63+
/// Consider using it in combination with [AnimationBuilder] as animation argument
64+
///
65+
/// The indicator controller will be passed as the third argument to the [builder] method.
66+
///
67+
/// To better understand this data, look at example app.
1968
final IndicatorController controller;
2069

2170
CustomRefreshIndicator({
@@ -53,7 +102,7 @@ class _CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
53102
AnimationController _animationController;
54103
IndicatorController _customRefreshIndicatorController;
55104

56-
/// Keeps current custom refresh indicator data
105+
/// Current [IndicatorController]
57106
IndicatorController get controller => _customRefreshIndicatorController;
58107

59108
static const double _kPositionLimit = 1.5;

0 commit comments

Comments
 (0)