@@ -15,11 +15,17 @@ typedef StarColorGetter = Color Function(int index);
1515class WarpIndicator extends StatefulWidget {
1616 final Widget child;
1717 final int starsCount;
18+ final OnRefresh onRefresh;
19+ final IndicatorController ? controller;
1820 final Color skyColor;
1921 final StarColorGetter starColorGetter;
22+ final Key ? indicatorKey;
2023
2124 const WarpIndicator ({
2225 Key ? key,
26+ this .indicatorKey,
27+ this .controller,
28+ required this .onRefresh,
2329 required this .child,
2430 this .starsCount = 30 ,
2531 this .skyColor = Colors .black,
@@ -37,7 +43,6 @@ class _WarpIndicatorState extends State<WarpIndicator>
3743 with SingleTickerProviderStateMixin {
3844 static const _indicatorSize = 150.0 ;
3945 final _random = Random ();
40- final _helper = IndicatorStateHelper ();
4146 WarpAnimationState _state = WarpAnimationState .stopped;
4247
4348 List <Star > stars = [];
@@ -112,10 +117,19 @@ class _WarpIndicatorState extends State<WarpIndicator>
112117 @override
113118 Widget build (BuildContext context) {
114119 return CustomRefreshIndicator (
120+ key: widget.indicatorKey,
121+ controller: widget.controller,
115122 offsetToArmed: _indicatorSize,
116123 leadingGlowVisible: false ,
117124 trailingGlowVisible: false ,
118- onRefresh: () => Future .delayed (const Duration (seconds: 2 )),
125+ onRefresh: widget.onRefresh,
126+ onStateChanged: (change) {
127+ if (change.didChange (to: IndicatorState .loading)) {
128+ _startShakeAnimation ();
129+ } else if (change.didChange (to: IndicatorState .idle)) {
130+ _stopShakeAnimation ();
131+ }
132+ },
119133 child: widget.child,
120134 builder: (
121135 BuildContext context,
@@ -144,18 +158,6 @@ class _WarpIndicatorState extends State<WarpIndicator>
144158 AnimatedBuilder (
145159 animation: animation,
146160 builder: (context, _) {
147- _helper.update (controller.state);
148- if (_helper.didStateChange (
149- to: IndicatorState .loading,
150- )) {
151- SchedulerBinding .instance
152- ? .addPostFrameCallback ((_) => _startShakeAnimation ());
153- } else if (_helper.didStateChange (
154- to: IndicatorState .idle,
155- )) {
156- SchedulerBinding .instance
157- ? .addPostFrameCallback ((_) => _stopShakeAnimation ());
158- }
159161 return Transform .scale (
160162 scale: _scaleTween.transform (controller.value),
161163 child: Builder (builder: (context) {
0 commit comments