@@ -277,21 +277,34 @@ class CameraPickerState extends State<CameraPicker> {
277
277
/// * SDK < 29: /sdcard/DCIM/camera .
278
278
/// * SDK >= 29: ${cacheDir}/ .
279
279
Future <void > initStorePath () async {
280
- /// Get device info before the path initialized.
281
- await DeviceUtils .getDeviceInfo ();
280
+ try {
281
+ /// Get device info before the path initialized.
282
+ await DeviceUtils .getDeviceInfo ();
282
283
283
- if (Platform .isAndroid) {
284
- if (DeviceUtils .isLowerThanAndroidQ) {
285
- cacheFilePath =
286
- '${(await getExternalStorageDirectory ()).path }/DCIM/Camera/' ;
284
+ if (Platform .isAndroid) {
285
+ if (DeviceUtils .isLowerThanAndroidQ) {
286
+ cacheFilePath =
287
+ '${(await getExternalStorageDirectory ()).path }/DCIM/Camera/' ;
288
+ } else {
289
+ cacheFilePath = (await getTemporaryDirectory ()).path;
290
+ }
287
291
} else {
288
- cacheFilePath = (await getTemporaryDirectory ()).path;
292
+ cacheFilePath = (await getApplicationDocumentsDirectory ()).path;
289
293
}
290
- } else {
291
- cacheFilePath = (await getApplicationDocumentsDirectory ()).path;
292
- }
293
- if (cacheFilePath != null ) {
294
- cacheFilePath += '/cameraPicker' ;
294
+ if (cacheFilePath != null ) {
295
+ cacheFilePath += '/cameraPicker' ;
296
+
297
+ /// Check if the directory is exist.
298
+ final Directory directory = Directory (cacheFilePath);
299
+ if (! directory.existsSync ()) {
300
+ /// Create the directory recursively.
301
+ await directory.create (recursive: true );
302
+ }
303
+ } else {
304
+ realDebugPrint ('Failed to initialize path: Still null.' );
305
+ }
306
+ } catch (e) {
307
+ realDebugPrint ('Error when initializing store path: $e ' );
295
308
}
296
309
}
297
310
0 commit comments