1
- import 'package:camelus/config/palette.dart' ;
1
+ import 'package:camelus/config/palette.dart' ;
2
2
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart' ;
3
3
import 'package:flutter/material.dart' ;
4
4
5
+ /// A custom refresh indicator widget that displays a message instead of the usual indicator
6
+ ///
7
+ /// This widget wraps around a child widget and displays a custom indicator with a "no need" message.
5
8
class RefreshIndicatorNoNeed extends StatelessWidget {
6
9
final Widget child;
7
- final Future <void > Function () onRefresh;
10
+ final Future <void > Function () onRefresh; // The callback function to trigger the refresh.
8
11
9
12
const RefreshIndicatorNoNeed ({
10
13
Key ? key,
11
14
required this .child,
12
- required this .onRefresh,
15
+ required this .onRefresh, // Function that handles the refresh logic.
13
16
}) : super (key: key);
14
17
15
18
@override
16
19
Widget build (BuildContext context) {
17
20
return CustomRefreshIndicator (
21
+ // Custom builder for the refresh indicator.
18
22
builder: (
19
23
BuildContext context,
20
24
Widget child,
@@ -23,49 +27,56 @@ class RefreshIndicatorNoNeed extends StatelessWidget {
23
27
return Stack (
24
28
children: < Widget > [
25
29
_MyIndicator (
30
+ // Pass the indicator's progress value and loading state to custom indicator widget.
26
31
value: controller.value,
27
32
loading: controller.state.isLoading,
28
33
),
34
+ // Translate the child widget vertically based on the progress of the refresh indicator.
29
35
Transform .translate (
30
36
offset: Offset (0 , controller.value * 50 ),
31
37
child: child,
32
38
),
33
39
],
34
40
);
35
41
},
42
+ // Function to trigger the refresh when the user pulls to refresh.
36
43
onRefresh: onRefresh,
37
- child: child,
44
+ child: child, // Pass the child widget to be wrapped by the refresh indicator.
38
45
);
39
46
}
40
47
}
41
48
49
+ /// A custom indicator widget that displays a message based on the refresh progress.
50
+ ///
51
+ /// This widget is shown when the refresh indicator is active and shows a "no need" message.
42
52
class _MyIndicator extends StatelessWidget {
43
- final double value;
44
- final bool loading;
53
+ final double value; // The progress value of the refresh indicator.
54
+ final bool loading; // The loading state of the refresh indicator.
45
55
46
56
const _MyIndicator ({
47
57
super .key,
48
- required this .value,
49
- required this .loading,
58
+ required this .value, // The current progress value (from 0 to 1).
59
+ required this .loading, // Whether the indicator is currently loading.
50
60
});
51
61
52
62
@override
53
63
Widget build (BuildContext context) {
54
- if (value == 0 ) return Container ();
64
+ if (value == 0 ) return Container (); // Return empty container if no progress is made.
65
+
55
66
return Padding (
56
67
padding: const EdgeInsets .only (top: 28 ),
57
68
child: Row (
58
- mainAxisAlignment: MainAxisAlignment .center,
69
+ mainAxisAlignment: MainAxisAlignment .center,
59
70
children: [
60
71
Container (
61
- padding: const EdgeInsets .fromLTRB (20 , 10 , 20 , 10 ),
72
+ padding: const EdgeInsets .fromLTRB (20 , 10 , 20 , 10 ),
62
73
decoration: BoxDecoration (
63
- borderRadius: BorderRadius .circular (20 ),
64
- color: Palette .extraDarkGray,
74
+ borderRadius: BorderRadius .circular (20 ),
75
+ color: Palette .extraDarkGray,
65
76
),
66
77
child: const Text (
67
- 'no need π' ,
68
- style: TextStyle (color: Palette .white, fontSize: 18 ),
78
+ 'no need π' , // The custom message displayed when the refresh indicator is active.
79
+ style: TextStyle (color: Palette .white, fontSize: 18 ), // Text style for the message.
69
80
),
70
81
),
71
82
],
0 commit comments