@@ -13,12 +13,38 @@ class CustomMaterialIndicatorScreen extends StatefulWidget {
13
13
class _CustomMaterialIndicatorScreenState extends State <CustomMaterialIndicatorScreen > {
14
14
final _controller = IndicatorController ();
15
15
16
+ bool _useCustom = true ;
17
+
18
+ void _toggleCustom (bool useCustom) {
19
+ // if no change exit
20
+ if (_useCustom == useCustom) return ;
21
+
22
+ setState (() {
23
+ _useCustom = useCustom;
24
+ });
25
+ }
26
+
16
27
@override
17
28
Widget build (BuildContext context) {
29
+ final child = ExampleList (
30
+ itemCount: 12 ,
31
+ physics: AlwaysScrollableScrollPhysics (
32
+ parent: _useCustom ? ClampingWithOverscrollPhysics (state: _controller) : const ClampingScrollPhysics (),
33
+ ),
34
+ );
18
35
return Scaffold (
19
36
backgroundColor: appBackgroundColor,
20
- appBar: const ExampleAppBar (
37
+ appBar: ExampleAppBar (
21
38
elevation: 0 ,
39
+ actions: [
40
+ Text (
41
+ _useCustom ? "CustomMaterialIndicator" : "RefreshIndicator" ,
42
+ ),
43
+ Switch (
44
+ value: _useCustom,
45
+ onChanged: _toggleCustom,
46
+ ),
47
+ ],
22
48
),
23
49
body: SafeArea (
24
50
child: Container (
@@ -28,29 +54,22 @@ class _CustomMaterialIndicatorScreenState extends State<CustomMaterialIndicatorS
28
54
color: const Color (0xFFE2D8D7 ),
29
55
),
30
56
),
31
- child: CustomMaterialIndicator (
32
- controller: _controller,
33
- clipBehavior: Clip .antiAlias,
34
- trigger: IndicatorTrigger .bothEdges,
35
- triggerMode: IndicatorTriggerMode .anywhere,
36
- onRefresh: () => Future .delayed (const Duration (seconds: 2 )),
37
- indicatorBuilder: (context, controller) {
38
- return const Icon (
39
- Icons .ac_unit,
40
- color: appContentColor,
41
- size: 30 ,
42
- );
43
- },
44
- scrollableBuilder: (context, child, controller) {
45
- return child;
46
- },
47
- child: ExampleList (
48
- itemCount: 12 ,
49
- physics: AlwaysScrollableScrollPhysics (
50
- parent: ClampingWithOverscrollPhysics (state: _controller),
51
- ),
52
- ),
53
- ),
57
+ child: _useCustom
58
+ ? CustomMaterialIndicator (
59
+ clipBehavior: Clip .antiAlias,
60
+ trigger: IndicatorTrigger .bothEdges,
61
+ triggerMode: IndicatorTriggerMode .anywhere,
62
+ onRefresh: () => Future .delayed (const Duration (seconds: 2 )),
63
+ scrollableBuilder: (context, child, controller) {
64
+ return child;
65
+ },
66
+ child: child,
67
+ )
68
+ : RefreshIndicator (
69
+ onRefresh: () => Future .delayed (const Duration (seconds: 2 )),
70
+ triggerMode: RefreshIndicatorTriggerMode .anywhere,
71
+ child: child,
72
+ ),
54
73
),
55
74
),
56
75
);
0 commit comments