11import 'package:custom_refresh_indicator/custom_refresh_indicator.dart' ;
2- import 'package:example/indicators/custom_indicator.dart' ;
32import 'package:flutter/material.dart' ;
43
54class _Cloud {
@@ -33,11 +32,9 @@ class _Cloud {
3332
3433/// Desgin by Katarzyna Klyta kasia@klyta.it
3534class PlaneIndicator extends StatefulWidget {
36- final IndicatorController controller;
3735 final Widget child;
3836 const PlaneIndicator ({
3937 @required this .child,
40- @required this .controller,
4138 });
4239
4340 @override
@@ -52,7 +49,6 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
5249
5350 @override
5451 void initState () {
55- _prevState = widget.controller.state;
5652 _planeController = AnimationController (
5753 vsync: this ,
5854 duration: const Duration (milliseconds: 500 ),
@@ -66,39 +62,39 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
6662 _Cloud (
6763 color: _Cloud ._dark,
6864 initialValue: 0.6 ,
69- dy: 17.5 ,
65+ dy: 10.0 ,
7066 image: AssetImage (_Cloud ._assets[1 ]),
7167 width: 100 ,
7268 duration: Duration (milliseconds: 1600 ),
7369 ),
7470 _Cloud (
7571 color: _Cloud ._light,
7672 initialValue: 0.15 ,
77- dy: 35 ,
73+ dy: 25.0 ,
7874 image: AssetImage (_Cloud ._assets[3 ]),
7975 width: 40 ,
8076 duration: Duration (milliseconds: 1600 ),
8177 ),
8278 _Cloud (
8379 color: _Cloud ._light,
8480 initialValue: 0.3 ,
85- dy: 75 ,
81+ dy: 65.0 ,
8682 image: AssetImage (_Cloud ._assets[2 ]),
8783 width: 60 ,
8884 duration: Duration (milliseconds: 1600 ),
8985 ),
9086 _Cloud (
9187 color: _Cloud ._dark,
9288 initialValue: 0.8 ,
93- dy: 80 ,
89+ dy: 70.0 ,
9490 image: AssetImage (_Cloud ._assets[3 ]),
9591 width: 100 ,
9692 duration: Duration (milliseconds: 1600 ),
9793 ),
9894 _Cloud (
9995 color: _Cloud ._normal,
10096 initialValue: 0.0 ,
101- dy: 110 ,
97+ dy: 10 ,
10298 image: AssetImage (_Cloud ._assets[0 ]),
10399 width: 80 ,
104100 duration: Duration (milliseconds: 1600 ),
@@ -143,6 +139,8 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
143139 super .dispose ();
144140 }
145141
142+ static const _offsetToArmed = 150.0 ;
143+
146144 @override
147145 Widget build (BuildContext context) {
148146 final screenWidth = MediaQuery .of (context).size.width;
@@ -163,15 +161,16 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
163161 },
164162 );
165163 return CustomRefreshIndicator (
164+ offsetToArmed: _offsetToArmed,
166165 child: widget.child,
167166 onRefresh: () => Future .delayed (const Duration (seconds: 3 )),
168167 builder:
169168 (BuildContext context, Widget child, IndicatorController controller) {
170169 return AnimatedBuilder (
171- animation: widget. controller,
172- child: widget. child,
170+ animation: controller,
171+ child: child,
173172 builder: (context, child) {
174- final currentState = widget. controller.state;
173+ final currentState = controller.state;
175174 if (_prevState == IndicatorState .armed &&
176175 currentState == IndicatorState .loading) {
177176 _startCloudAnimation ();
@@ -191,7 +190,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
191190 children: < Widget > [
192191 if (_prevState != IndicatorState .idle)
193192 Container (
194- height: 150 * widget. controller.value,
193+ height: _offsetToArmed * controller.value,
195194 color: Color (0xFFFDFEFF ),
196195 width: double .infinity,
197196 child: AnimatedBuilder (
@@ -206,7 +205,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
206205 ((screenWidth + cloud.width) *
207206 cloud.controller.value) -
208207 cloud.width,
209- cloud.dy * widget. controller.value,
208+ cloud.dy * controller.value,
210209 ),
211210 child: OverflowBox (
212211 minWidth: cloud.width,
@@ -241,7 +240,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
241240 ),
242241 ),
243242 Transform .translate (
244- offset: Offset (0.0 , 150 * widget. controller.value),
243+ offset: Offset (0.0 , _offsetToArmed * controller.value),
245244 child: child,
246245 ),
247246 ],
@@ -252,10 +251,3 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
252251 );
253252 }
254253}
255-
256- CustomIndicatorConfig planeIndicator = CustomIndicatorConfig (
257- builder: (context, child, data) => PlaneIndicator (
258- child: child,
259- controller: data,
260- ),
261- );
0 commit comments