Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit a49fbc6

Browse files
committed
Removed late modifiers from stars bg
1 parent 59e0c95 commit a49fbc6

4 files changed

Lines changed: 26 additions & 641 deletions

File tree

lib/weather/bg/weather_bg.dart

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:hackru/weather/bg/weather_color_bg.dart';
33
import 'package:hackru/weather/bg/weather_night_star_bg.dart';
4-
import 'package:hackru/weather/bg/weather_rain_snow_bg.dart';
5-
import 'package:hackru/weather/bg/weather_thunder_bg.dart';
64

75
import '../utils/weather_type.dart';
86

@@ -103,28 +101,6 @@ class WeatherItemBg extends StatelessWidget {
103101
return Container();
104102
}
105103

106-
/// 构建雷暴效果
107-
Widget _buildThunderBg() {
108-
if (weatherType == WeatherType.thunder) {
109-
return WeatherThunderBg(
110-
weatherType: weatherType,
111-
);
112-
}
113-
return Container();
114-
}
115-
116-
/// 构建雨雪背景效果
117-
Widget _buildRainSnowBg() {
118-
if (WeatherUtil.isSnowRain(weatherType)) {
119-
return WeatherRainSnowBg(
120-
weatherType: weatherType,
121-
viewWidth: width,
122-
viewHeight: height,
123-
);
124-
}
125-
return Container();
126-
}
127-
128104
@override
129105
Widget build(BuildContext context) {
130106
return Container(
@@ -136,8 +112,6 @@ class WeatherItemBg extends StatelessWidget {
136112
WeatherColorBg(
137113
weatherType: weatherType,
138114
),
139-
_buildRainSnowBg(),
140-
_buildThunderBg(),
141115
_buildNightStarBg(),
142116
],
143117
),

lib/weather/bg/weather_night_star_bg.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

206206
class _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

237237
class _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

Comments
 (0)