|
@@ -45,8 +45,8 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
45
|
45
|
void initState() {
|
46
|
46
|
super.initState();
|
47
|
47
|
widget.controller._setCountController(_countController);
|
48
|
|
- widget.controller._recordingState.addListener(_onUpdateRecordingState);
|
49
|
|
- widget.controller._isCountingDown.addListener(_onUpdateIsCountingDown);
|
|
48
|
+ widget.controller.recordingState.addListener(_onUpdateRecordingState);
|
|
49
|
+ widget.controller.isCountingDown.addListener(_onUpdateIsCountingDown);
|
50
|
50
|
}
|
51
|
51
|
|
52
|
52
|
///更新录像状态
|
|
@@ -71,7 +71,7 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
71
|
71
|
///更新倒计时状态
|
72
|
72
|
void _onUpdateIsCountingDown() {
|
73
|
73
|
setState(() {
|
74
|
|
- _isCountingDown = widget.controller._isCountingDown.value;
|
|
74
|
+ _isCountingDown = widget.controller.isCounting;
|
75
|
75
|
});
|
76
|
76
|
}
|
77
|
77
|
|
|
@@ -79,8 +79,9 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
79
|
79
|
void dispose() {
|
80
|
80
|
super.dispose();
|
81
|
81
|
_recordingTimer?.cancel();
|
82
|
|
- widget.controller._recordingState.removeListener(_onUpdateRecordingState);
|
83
|
|
- widget.controller._isCountingDown.removeListener(_onUpdateIsCountingDown);
|
|
82
|
+ _countController.dispose();
|
|
83
|
+ widget.controller.recordingState.removeListener(_onUpdateRecordingState);
|
|
84
|
+ widget.controller.isCountingDown.removeListener(_onUpdateIsCountingDown);
|
84
|
85
|
}
|
85
|
86
|
|
86
|
87
|
@override
|
|
@@ -180,9 +181,8 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
180
|
181
|
width: 17.5.r,
|
181
|
182
|
height: 17.5.r,
|
182
|
183
|
decoration: BoxDecoration(
|
183
|
|
- color: widget.controller._recordingState.value
|
184
|
|
- ? Colors.red
|
185
|
|
- : Colors.white,
|
|
184
|
+ color:
|
|
185
|
+ widget.controller.isRecording ? Colors.red : Colors.white,
|
186
|
186
|
shape: BoxShape.circle),
|
187
|
187
|
));
|
188
|
188
|
|
|
@@ -229,7 +229,7 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
229
|
229
|
int delay = await SpUtil.getDelayShotTime();
|
230
|
230
|
_countController.startCount(isDelay ? delay : 0);
|
231
|
231
|
if (isDelay) {
|
232
|
|
- widget.controller._isCountingDown.value = true;
|
|
232
|
+ widget.controller.isCounting = true;
|
233
|
233
|
}
|
234
|
234
|
}
|
235
|
235
|
|
|
@@ -250,7 +250,7 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
250
|
250
|
///关闭视频
|
251
|
251
|
void _stopVideo() {
|
252
|
252
|
widget.onStopVideo();
|
253
|
|
- widget.controller._isCountingDown.value = false;
|
|
253
|
+ widget.controller.isCounting = false;
|
254
|
254
|
}
|
255
|
255
|
|
256
|
256
|
///拍照倒计时
|
|
@@ -259,16 +259,22 @@ class _VideoOperationViewState extends State<VideoOperationView> {
|
259
|
259
|
return;
|
260
|
260
|
}
|
261
|
261
|
widget.onTakePhoto();
|
262
|
|
- widget.controller._isCountingDown.value = false;
|
|
262
|
+ widget.controller.isCounting = false;
|
263
|
263
|
}
|
264
|
264
|
}
|
265
|
265
|
|
266
|
266
|
class VideoOperationViewController {
|
267
|
267
|
CountDownTextController? _countController;
|
268
|
268
|
|
269
|
|
- final ValueNotifier<bool> _recordingState = ValueNotifier(false);
|
|
269
|
+ ValueNotifier<bool>? _recordingState;
|
270
|
270
|
|
271
|
|
- final ValueNotifier<bool> _isCountingDown = ValueNotifier(false);
|
|
271
|
+ ValueNotifier<bool> get recordingState =>
|
|
272
|
+ _recordingState ??= ValueNotifier(false);
|
|
273
|
+
|
|
274
|
+ ValueNotifier<bool>? _isCountingDown;
|
|
275
|
+
|
|
276
|
+ ValueNotifier<bool> get isCountingDown =>
|
|
277
|
+ _isCountingDown ??= ValueNotifier(false);
|
272
|
278
|
|
273
|
279
|
void _setCountController(CountDownTextController controller) {
|
274
|
280
|
_countController = controller;
|
|
@@ -276,16 +282,22 @@ class VideoOperationViewController {
|
276
|
282
|
|
277
|
283
|
void dispose() {
|
278
|
284
|
_countController?.stopCount();
|
279
|
|
- _recordingState.dispose();
|
280
|
|
- _isCountingDown.dispose();
|
|
285
|
+ _recordingState?.dispose();
|
|
286
|
+ _recordingState = null;
|
|
287
|
+ _isCountingDown?.dispose();
|
|
288
|
+ _isCountingDown = null;
|
281
|
289
|
}
|
282
|
290
|
|
283
|
291
|
void updateRecordingState(bool isRecording) {
|
284
|
|
- if (_recordingState.value == isRecording) {
|
|
292
|
+ if (recordingState.value == isRecording) {
|
285
|
293
|
return;
|
286
|
294
|
}
|
287
|
|
- _recordingState.value = isRecording;
|
|
295
|
+ recordingState.value = isRecording;
|
288
|
296
|
}
|
289
|
297
|
|
290
|
|
- bool get isRecording => _recordingState.value;
|
|
298
|
+ bool get isRecording => recordingState.value;
|
|
299
|
+
|
|
300
|
+ bool get isCounting => isCountingDown.value;
|
|
301
|
+
|
|
302
|
+ set isCounting(bool bo) => isCountingDown.value = bo;
|
291
|
303
|
}
|