Skip to content

Commit 29a83af

Browse files
committed
⚡ Enhance error handling.
1 parent 51456f1 commit 29a83af

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/src/widget/camera_picker.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:io';
77

88
import 'package:flutter/material.dart';
9+
import 'package:flutter/scheduler.dart';
910
import 'package:flutter/services.dart';
1011
import 'package:camera/camera.dart';
1112
import 'package:path_provider/path_provider.dart';
@@ -244,14 +245,28 @@ class CameraPickerState extends State<CameraPicker> {
244245
if (Platform.isIOS) {
245246
SystemChrome.setEnabledSystemUIOverlays(<SystemUiOverlay>[]);
246247
}
247-
initStorePath();
248-
initCameras();
248+
249+
try {
250+
initStorePath();
251+
initCameras();
252+
} catch (e) {
253+
realDebugPrint('Error when initializing: $e');
254+
if (context == null) {
255+
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
256+
Navigator.of(context).pop();
257+
});
258+
} else {
259+
Navigator.of(context).pop();
260+
}
261+
}
249262
}
250263

251264
@override
252265
void dispose() {
253266
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
254267
cameraController?.dispose();
268+
recordDetectTimer?.cancel();
269+
recordCountdownTimer?.cancel();
255270
super.dispose();
256271
}
257272

0 commit comments

Comments
 (0)