@@ -2,47 +2,48 @@ import 'package:flutter/material.dart';
2
2
import '../../gamma_smart_pagination.dart' ;
3
3
import '../helpers/extensions.dart' ;
4
4
5
- /// [GammaSmartPagination] is a wrapper widget for scrollable widgets that enables
5
+ /// Wrapper widget for scrollable widgets that enables
6
6
/// pull to refresh and infinite scrolling pagination.
7
7
class GammaSmartPagination extends StatefulWidget {
8
- /// [GammaController] that will be used to control the status of the pagination.
8
+ /// Controls for the status of the pagination.
9
9
final GammaController gammaSmartController;
10
10
11
- /// [ScrollController] that will be used to control the scroll position of the list internally.
11
+ /// Controls the scroll position of the list internally.
12
12
final ScrollController scrollController;
13
13
14
- /// [onLoadMore] is the callback that will be called when the user scrolls to the bottom of the list.
14
+ /// Callback that will be called when the user scrolls to the bottom of the list.
15
15
final Future <void > Function ()? onLoadMore;
16
16
17
- /// [onRefresh] is the callback that will be called when the user pulls down the list.
17
+ /// Callback that will be called when the user pulls down the list.
18
18
final Future <void > Function ()? onRefresh;
19
19
20
- /// [@required][child] is the scrollable child widget that will be wrapped by the GammaSmartPagination widget.
20
+ /// Scrollable child widget that will be wrapped by the GammaSmartPagination widget.
21
+ /// It must have physics set to [NeverScrollableScrollPhysics] and shrinkWrap set to true.
21
22
final Widget child;
22
23
23
- /// [@required][itemCount] is the number of items in the list.
24
+ /// Number of items in the list.
24
25
final int itemCount;
25
26
26
- /// [noInitialDataWidget] is the widget that will be displayed when the list is empty.
27
+ /// Widget that will be displayed when the list is empty.
27
28
final Widget ? noInitialDataWidget;
28
29
29
- /// [noMoreDataWidget] is the widget that will be displayed when the list has loaded all the data.
30
+ /// Widget that will be displayed when the list has loaded all the data.
30
31
final Widget ? noMoreDataWidget;
31
32
32
- /// [loadingFailedWidget] is the widget that will be displayed when the list failed to load more data.
33
+ /// Widget that will be displayed when the list failed to load more data.
33
34
final Widget ? loadingFailedWidget;
34
35
35
- /// [refreshFailedWidget] is the widget that will be displayed when the list failed to refresh.
36
+ /// Widget that will be displayed when the list failed to refresh.
36
37
final Widget ? refreshFailedWidget;
37
38
38
- /// [loadingIndicator] is the widget that will be displayed when the list is loading more data.
39
+ /// Widget that will be displayed when the list is loading more data.
39
40
final Widget ? loadingIndicator;
40
41
41
- /// [enableLogging] is a boolean that will enable logging when set to true.
42
+ /// Enable logging when set to true.
42
43
final bool enableLogging;
43
44
44
- /// [GammaSmartPagination] is a 2 in 1 widget that acts as a wrapper for scrollable widgets.
45
- /// It enables pull to refresh and infinite scrolling pagination.
45
+ /// Wrapper for scrollable widgets that enables
46
+ /// pull to refresh and infinite scrolling pagination.
46
47
///
47
48
/// Typically used as wrapper for [ListView] , [GridView] .
48
49
///
@@ -71,13 +72,13 @@ class GammaSmartPagination extends StatefulWidget {
71
72
}
72
73
73
74
class _GammaSmartPaginationState extends State <GammaSmartPagination > {
74
- /// [GammaController] that will be used to control the status of the pagination.
75
+ /// Controls the status of the pagination.
75
76
GammaController get _customController => widget.gammaSmartController;
76
77
77
- /// [ScrollController] that will be used to control the scroll position of the list internally.
78
+ /// Controls the scroll position of the list internally.
78
79
ScrollController get _scrollController => widget.scrollController;
79
80
80
- /// [sensitivityFactor] is the factor that will be used to determine if the user has reached the bottom of the list.
81
+ /// factor to determine if the user has reached the bottom of the list.
81
82
static const double _sensitivityFactor = 200.0 ;
82
83
83
84
final wipedGrayTextColorStyle = TextStyle (color: Colors .grey.shade400);
@@ -97,32 +98,33 @@ class _GammaSmartPaginationState extends State<GammaSmartPagination> {
97
98
98
99
@override
99
100
void initState () {
100
- _scrollController.addListener (onBottomReached );
101
+ _scrollController.addListener (_onBottomReached );
101
102
super .initState ();
102
103
}
103
104
104
- /// [onBottomReached] is called when the user scrolls to the bottom of the list.
105
- void onBottomReached () {
105
+ /// Callback when the user scrolls to the bottom of the list.
106
+ void _onBottomReached () {
106
107
final maxScroll = _scrollController.position.maxScrollExtent;
107
108
final currentScroll = _scrollController.position.pixels;
108
109
if (currentScroll >= (maxScroll - _sensitivityFactor)) {
109
110
if (_customController.shouldLoadMore && currentScroll > 0 ) {
110
111
_logLoadMoreCalled ();
111
- onLoadMore ();
112
+ _onLoadMore ();
112
113
}
113
114
}
114
115
}
115
116
116
- /// [onLoadMore] is called when the user scrolls to the bottom of the list.
117
- Future <void > onLoadMore () async {
117
+ /// Callback when the user scrolls to the bottom of the list.
118
+ Future <void > _onLoadMore () async {
118
119
_customController.setLoading ();
119
120
await widget.onLoadMore? .call ();
120
121
}
121
122
122
- /// [onRefresh] is called when the user pulls down the list.
123
- Future <void > onRefresh () async {
123
+ /// Called when the user pulls down the list.
124
+ Future <void > _onRefresh () async {
125
+ _logRefreshCalled ();
124
126
_customController.setRefreshing ();
125
- await widget.onRefresh? .call ();
127
+ return await widget.onRefresh? .call ();
126
128
}
127
129
128
130
@override
@@ -137,10 +139,7 @@ class _GammaSmartPaginationState extends State<GammaSmartPagination> {
137
139
138
140
RefreshIndicator _buildDataWidget () {
139
141
return RefreshIndicator (
140
- onRefresh: () async {
141
- _logRefreshCalled ();
142
- return widget.onRefresh? .call ();
143
- },
142
+ onRefresh: () async => _onRefresh (),
144
143
child: SingleChildScrollView (
145
144
controller: _scrollController,
146
145
physics: const AlwaysScrollableScrollPhysics (),
0 commit comments