36 lines
1.3 KiB
Dart
36 lines
1.3 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
|
|
class ImageCustomProvider {
|
|
static ImageProvider<Object> getImageProvider(AppContext appContext, String? imageId, String imageSource) {
|
|
VisitAppContext visitAppContext = appContext.getContext();
|
|
try {
|
|
if(appContext.getContext().localPath != null && visitAppContext.configuration != null) {
|
|
Directory configurationDirectory = Directory('${visitAppContext.localPath!}/${visitAppContext.configuration!.id!}');
|
|
List<FileSystemEntity> fileList = configurationDirectory.listSync();
|
|
|
|
if(imageId != null && 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");
|
|
print(imageId);
|
|
return CachedNetworkImageProvider(imageSource);
|
|
}
|
|
}
|
|
|