@@ -23,16 +23,16 @@ class _WeatherNightStarBgState extends State<WeatherNightStarBg>
2323 List <_StarParam > _starParams = [];
2424 List <_MeteorParam > _meteorParams = [];
2525 WeatherDataState _state = WeatherDataState .init;
26- late double width;
27- late double height;
28- late double widthRatio;
26+ double ? width;
27+ double ? height;
28+ double ? widthRatio;
2929
3030 /// 准备星星的参数信息
3131 void fetchData () async {
3232 Size ? size = SizeInherited .of (context)? .size;
3333 width = size? .width ?? double .infinity;
3434 height = size? .height ?? double .infinity;
35- widthRatio = (height * 2 ) / width;
35+ widthRatio = (height! * 2 ) / width! ;
3636 print ("width ratio $widthRatio " );
3737 weatherPrint ("开始准备星星参数" );
3838 _state = WeatherDataState .loading;
@@ -150,10 +150,10 @@ class _StarPainter extends CustomPainter {
150150 < Color > [const Color (0xFFFFFFFF ), const Color (0x00FFFFFF )],
151151 );
152152 _meteorPaint.shader = gradient;
153- canvas.rotate (pi * param.radians);
153+ canvas.rotate (pi * param.radians! );
154154 canvas.scale (widthRatio);
155155 canvas.translate (
156- param.translateX, tan (pi * 0.1 ) * _meteorWidth + param.translateY);
156+ param.translateX! , tan (pi * 0.1 ) * _meteorWidth + param.translateY! );
157157 canvas.drawRRect (
158158 RRect .fromLTRBAndCorners (0 , 0 , _meteorWidth, _meteorHeight,
159159 topLeft: _radius,
@@ -191,8 +191,8 @@ class _StarPainter extends CustomPainter {
191191 0 ,
192192 ]);
193193 _paint.colorFilter = identity;
194- canvas.scale (param.scale);
195- canvas.drawCircle (Offset (param.x, param.y), 0.8 , _paint);
194+ canvas.scale (param.scale! );
195+ canvas.drawCircle (Offset (param.x! , param.y! ), 0.8 , _paint);
196196 canvas.restore ();
197197 param.move ();
198198 }
@@ -204,11 +204,11 @@ class _StarPainter extends CustomPainter {
204204}
205205
206206class _MeteorParam {
207- late double translateX;
208- late double translateY;
209- late double radians;
207+ double ? translateX;
208+ double ? translateY;
209+ double ? radians;
210210
211- late double width, height, widthRatio;
211+ double ? width, height, widthRatio;
212212
213213 /// 初始化数据
214214 void init (width, height, widthRatio) {
@@ -220,53 +220,53 @@ class _MeteorParam {
220220
221221 /// 重置数据
222222 void reset () {
223- translateX = width + Random ().nextDouble () * 20.0 * width;
223+ translateX = width! + Random ().nextDouble () * 20.0 * width! ;
224224 radians = - Random ().nextDouble () * 0.07 - 0.05 ;
225- translateY = Random ().nextDouble () * 0.5 * height * widthRatio;
225+ translateY = Random ().nextDouble () * 0.5 * height! * widthRatio! ;
226226 }
227227
228228 /// 移动
229229 void move () {
230- translateX -= 20 ;
231- if (translateX <= - 1.0 * width / widthRatio) {
230+ translateX = translateX ! + 20 ;
231+ if (translateX! <= - 1.0 * width! / widthRatio! ) {
232232 reset ();
233233 }
234234 }
235235}
236236
237237class _StarParam {
238238 /// x 坐标
239- late double x;
239+ double ? x;
240240
241241 /// y 坐标
242- late double y;
242+ double ? y;
243243
244244 /// 透明度值,默认为 0
245245 double alpha = 0.0 ;
246246
247247 /// 缩放
248- late double scale;
248+ double ? scale;
249249
250250 /// 是否反向动画
251251 bool reverse = false ;
252252
253253 /// 当前下标值
254254 int index;
255255
256- late double width;
256+ double ? width;
257257
258- late double height;
258+ double ? height;
259259
260- late double widthRatio;
260+ double ? widthRatio;
261261
262262 _StarParam (this .index);
263263
264264 void reset () {
265265 alpha = 0 ;
266266 double baseScale = index == 0 ? 0.7 : 0.5 ;
267- scale = (Random ().nextDouble () * 0.1 + baseScale) * widthRatio;
268- x = Random ().nextDouble () * 1 * width / scale;
269- y = Random ().nextDouble () * max (0.3 * height, 150 );
267+ scale = (Random ().nextDouble () * 0.1 + baseScale) * widthRatio! ;
268+ x = Random ().nextDouble () * 1 * width! / scale! ;
269+ y = Random ().nextDouble () * max (0.3 * height! , 150 );
270270 reverse = false ;
271271 }
272272
@@ -278,7 +278,7 @@ class _StarParam {
278278 alpha = Random ().nextDouble ();
279279 double baseScale = index == 0 ? 0.7 : 0.5 ;
280280 scale = (Random ().nextDouble () * 0.1 + baseScale) * widthRatio;
281- x = Random ().nextDouble () * 1 * width / scale;
281+ x = Random ().nextDouble () * 1 * width / scale! ;
282282 y = Random ().nextDouble () * max (0.3 * height, 150 );
283283 reverse = false ;
284284 }
0 commit comments