tablet-app/lib/Helpers/ImageCustomProvider.dart

35 lines
1.2 KiB
Dart

import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:tablet_app/Models/tabletContext.dart';
import 'package:tablet_app/app_context.dart';
class ImageCustomProvider {
static ImageProvider<Object> getImageProvider(AppContext appContext, String imageId, String imageSource) {
TabletAppContext tabletAppContext = appContext.getContext();
try {
if(appContext.getContext().localPath != null && tabletAppContext.configuration != null) {
Directory configurationDirectory = Directory('${tabletAppContext.localPath!}/${tabletAppContext.configuration!.id!}');
List<FileSystemEntity> fileList = configurationDirectory.listSync();
if(fileList.any((fileL) => fileL.uri.pathSegments.last.contains(imageId))) {
File file = File(fileList.firstWhere((fileL) => fileL.uri.pathSegments.last.contains(imageId)).path);
print("FILE EXISTT");
return FileImage(file);
}
}
} catch(e) {
print("Error getImageProvider");
print(e.toString());
}
// If localpath not found or file missing
print("MISSINGG FILE");
return CachedNetworkImageProvider(imageSource);
}
}