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

Commit 1c7dc3b

Browse files
authored
Merge pull request #101 from HackRU/UI-updates
UI updates
2 parents 6e5488e + bb37fc3 commit 1c7dc3b

5 files changed

Lines changed: 37 additions & 651 deletions

File tree

lib/ui/pages/qr_scanner/Scanner.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class _ScannerState extends State<Scanner> with SingleTickerProviderStateMixin {
2929
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
3030
AnimationController? _animationController;
3131
bool isPlaying = false;
32-
late MobileScannerController cameraController;
32+
MobileScannerController? cameraController;
3333
final TextEditingController _textFieldController = TextEditingController();
3434
CredManager? credManager;
3535

@@ -67,7 +67,7 @@ class _ScannerState extends State<Scanner> with SingleTickerProviderStateMixin {
6767
void dispose() {
6868
super.dispose();
6969
_animationController?.dispose();
70-
cameraController.dispose();
70+
cameraController!.dispose();
7171
}
7272

7373
@override
@@ -141,7 +141,8 @@ class _ScannerState extends State<Scanner> with SingleTickerProviderStateMixin {
141141
IconButton(
142142
iconSize: 80,
143143
icon: ValueListenableBuilder(
144-
valueListenable: cameraController.cameraFacingState,
144+
valueListenable:
145+
cameraController!.cameraFacingState,
145146
builder: (context, state, child) {
146147
switch (state as CameraFacing) {
147148
case CameraFacing.front:
@@ -159,7 +160,7 @@ class _ScannerState extends State<Scanner> with SingleTickerProviderStateMixin {
159160
}
160161
},
161162
),
162-
onPressed: () => cameraController.switchCamera(),
163+
onPressed: () => cameraController!.switchCamera(),
163164
),
164165
],
165166
),
@@ -178,10 +179,10 @@ class _ScannerState extends State<Scanner> with SingleTickerProviderStateMixin {
178179
isPlaying = !isPlaying;
179180
if (isPlaying) {
180181
_animationController?.forward();
181-
cameraController.stop();
182+
cameraController!.stop();
182183
} else {
183184
_animationController?.reverse();
184-
cameraController.start();
185+
cameraController!.start();
185186
}
186187
});
187188
}

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: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ class WeatherNightStarBg extends StatefulWidget {
1919

2020
class _WeatherNightStarBgState extends State<WeatherNightStarBg>
2121
with SingleTickerProviderStateMixin {
22-
late AnimationController _controller;
22+
AnimationController? _controller;
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;
3939
initStarParams();
4040
setState(() {
41-
_controller.repeat();
41+
_controller!.repeat();
4242
});
4343
_state = WeatherDataState.finish;
4444
}
@@ -63,15 +63,15 @@ class _WeatherNightStarBgState extends State<WeatherNightStarBg>
6363
/// 初始化动画信息
6464
_controller =
6565
AnimationController(duration: Duration(seconds: 5), vsync: this);
66-
_controller.addListener(() {
66+
_controller!.addListener(() {
6767
setState(() {});
6868
});
6969
super.initState();
7070
}
7171

7272
@override
7373
void dispose() {
74-
_controller.dispose();
74+
_controller!.dispose();
7575
super.dispose();
7676
}
7777

@@ -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)