mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
Added try catch file access
This commit is contained in:
parent
cdda7d1470
commit
387560fad7
@ -102,14 +102,19 @@ class CachedCustomResource extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<File?> _checkIfLocalResourceExists(TabletAppContext tabletAppContext) async {
|
Future<File?> _checkIfLocalResourceExists(TabletAppContext tabletAppContext) async {
|
||||||
Directory? appDocumentsDirectory = await getDownloadsDirectory();
|
try {
|
||||||
String localPath = appDocumentsDirectory!.path;
|
Directory? appDocumentsDirectory = await getDownloadsDirectory();
|
||||||
Directory configurationDirectory = Directory('$localPath/${tabletAppContext.configuration!.id}');
|
String localPath = appDocumentsDirectory!.path;
|
||||||
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
Directory configurationDirectory = Directory('$localPath/${tabletAppContext.configuration!.id}');
|
||||||
|
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
||||||
|
|
||||||
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(resourceDTO.id!))) {
|
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(resourceDTO.id!))) {
|
||||||
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(resourceDTO.id!)).path);
|
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(resourceDTO.id!)).path);
|
||||||
return file;
|
return file;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
print("ERROR _checkIfLocalResourceExists CachedCustomResource");
|
||||||
|
print(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -8,19 +8,25 @@ import 'package:tablet_app/app_context.dart';
|
|||||||
class ImageCustomProvider {
|
class ImageCustomProvider {
|
||||||
static ImageProvider<Object> getImageProvider(AppContext appContext, String imageId, String imageSource) {
|
static ImageProvider<Object> getImageProvider(AppContext appContext, String imageId, String imageSource) {
|
||||||
TabletAppContext tabletAppContext = appContext.getContext();
|
TabletAppContext tabletAppContext = appContext.getContext();
|
||||||
if(appContext.getContext().localPath != null && tabletAppContext.configuration != null) {
|
try {
|
||||||
Directory configurationDirectory = Directory('${tabletAppContext.localPath!}/${tabletAppContext.configuration!.id!}');
|
if(appContext.getContext().localPath != null && tabletAppContext.configuration != null) {
|
||||||
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
Directory configurationDirectory = Directory('${tabletAppContext.localPath!}/${tabletAppContext.configuration!.id!}');
|
||||||
|
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
||||||
|
|
||||||
print(fileList);
|
print(fileList);
|
||||||
|
|
||||||
if (fileList.isNotEmpty) {
|
if (fileList.isNotEmpty) {
|
||||||
File file = File(fileList.first.path);
|
File file = File(fileList.first.path);
|
||||||
print("FILE EXISTT");
|
print("FILE EXISTT");
|
||||||
return FileImage(file);
|
return FileImage(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch(e) {
|
||||||
|
print("Error getImageProvider");
|
||||||
|
print(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If localpath not found or file missing
|
// If localpath not found or file missing
|
||||||
print("MISSINGG FILE");
|
print("MISSINGG FILE");
|
||||||
return CachedNetworkImageProvider(imageSource);
|
return CachedNetworkImageProvider(imageSource);
|
||||||
|
|||||||
@ -165,14 +165,19 @@ class _PDFViewWidget extends State<PDFViewWidget> {
|
|||||||
} //_webView
|
} //_webView
|
||||||
|
|
||||||
Future<File?> _checkIfLocalResourceExists(TabletAppContext tabletAppContext, String resourceId) async {
|
Future<File?> _checkIfLocalResourceExists(TabletAppContext tabletAppContext, String resourceId) async {
|
||||||
Directory? appDocumentsDirectory = await getDownloadsDirectory();
|
try {
|
||||||
String localPath = appDocumentsDirectory!.path;
|
Directory? appDocumentsDirectory = await getDownloadsDirectory();
|
||||||
Directory configurationDirectory = Directory('$localPath/${tabletAppContext.configuration!.id}');
|
String localPath = appDocumentsDirectory!.path;
|
||||||
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
Directory configurationDirectory = Directory('$localPath/${tabletAppContext.configuration!.id}');
|
||||||
|
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
||||||
|
|
||||||
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(resourceId))) {
|
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(resourceId))) {
|
||||||
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(resourceId)).path);
|
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(resourceId)).path);
|
||||||
return file;
|
return file;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("ERROR _checkIfLocalResourceExists PDF");
|
||||||
|
print(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user