1+ import 'dart:async' ;
2+
13import 'package:custom_refresh_indicator/custom_refresh_indicator.dart' ;
24import 'package:flutter/material.dart' ;
35
@@ -14,19 +16,20 @@ class _Cloud {
1416 ];
1517
1618 AnimationController ? controller;
17- final Color ? color;
18- final AssetImage ? image;
19- final double ? width;
20- final double ? dy;
21- final double ? initialValue;
22- final Duration ? duration;
19+ final Color color;
20+ final AssetImage image;
21+ final double width;
22+ final double dy;
23+ final double initialValue;
24+ final Duration duration;
25+
2326 _Cloud ({
24- this .color,
25- this .image,
26- this .width,
27- this .dy,
28- this .initialValue,
29- this .duration,
27+ required this .color,
28+ required this .image,
29+ required this .width,
30+ required this .dy,
31+ required this .initialValue,
32+ required this .duration,
3033 });
3134}
3235
@@ -41,8 +44,7 @@ class PlaneIndicator extends StatefulWidget {
4144 State <PlaneIndicator > createState () => _PlaneIndicatorState ();
4245}
4346
44- class _PlaneIndicatorState extends State <PlaneIndicator >
45- with TickerProviderStateMixin {
47+ class _PlaneIndicatorState extends State <PlaneIndicator > with TickerProviderStateMixin {
4648 static final _planeTween = CurveTween (curve: Curves .easeInOut);
4749 late AnimationController _planeController;
4850
@@ -54,9 +56,16 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
5456 );
5557
5658 _setupCloudsAnimationControllers ();
59+ WidgetsBinding .instance.addPostFrameCallback ((_) => _precacheImages ());
5760 super .initState ();
5861 }
5962
63+ void _precacheImages () {
64+ for (final config in _clouds) {
65+ unawaited (precacheImage (config.image, context));
66+ }
67+ }
68+
6069 static final _clouds = [
6170 _Cloud (
6271 color: _Cloud ._dark,
@@ -162,8 +171,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
162171 ),
163172 builder: (BuildContext context, Widget ? child) {
164173 return Transform .translate (
165- offset: Offset (0.0 ,
166- 10 * (0.5 - _planeTween.transform (_planeController.value))),
174+ offset: Offset (0.0 , 10 * (0.5 - _planeTween.transform (_planeController.value))),
167175 child: child,
168176 );
169177 },
@@ -191,8 +199,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
191199 }
192200 },
193201 onRefresh: () => Future .delayed (const Duration (seconds: 3 )),
194- builder: (BuildContext context, Widget child,
195- IndicatorController controller) {
202+ builder: (BuildContext context, Widget child, IndicatorController controller) {
196203 return AnimatedBuilder (
197204 animation: controller,
198205 child: child,
@@ -214,10 +221,8 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
214221 for (final cloud in _clouds)
215222 Transform .translate (
216223 offset: Offset (
217- ((screenWidth + cloud.width! ) *
218- cloud.controller! .value) -
219- cloud.width! ,
220- cloud.dy! * controller.value,
224+ ((screenWidth + cloud.width) * cloud.controller! .value) - cloud.width,
225+ cloud.dy * controller.value,
221226 ),
222227 child: OverflowBox (
223228 minWidth: cloud.width,
@@ -227,7 +232,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
227232 alignment: Alignment .topLeft,
228233 child: Image (
229234 color: cloud.color,
230- image: cloud.image! ,
235+ image: cloud.image,
231236 fit: BoxFit .contain,
232237 ),
233238 ),
0 commit comments