getThumbnailFromPath method
Get the thumbnail from the first asset under the specific path entity. 获取指定路径下的第一个资源的缩略图数据
Implementation
@override
Future<Uint8List?> getThumbnailFromPath(
PathWrapper<AssetPathEntity> path,
) async {
try {
if (requestType == RequestType.audio) {
return null;
}
final int assetCount = path.assetCount ?? await path.path.assetCountAsync;
if (assetCount == 0) {
return null;
}
final List<AssetEntity> assets = await path.path.getAssetListRange(
start: 0,
end: 1,
);
if (assets.isEmpty) {
return null;
}
final AssetEntity asset = assets.single;
// Obtain the thumbnail only when the asset is image or video.
if (asset.type != AssetType.image && asset.type != AssetType.video) {
return null;
}
final Uint8List? data = await asset.thumbnailDataWithSize(
pathThumbnailSize,
);
final int index = _paths.indexWhere(
(PathWrapper<AssetPathEntity> p) => p.path == path.path,
);
if (index != -1) {
_paths[index] = _paths[index].copyWith(thumbnailData: data);
notifyListeners();
}
return data;
} catch (e, s) {
FlutterError.presentError(
FlutterErrorDetails(
exception: e,
stack: s,
library: packageName,
silent: true,
),
);
return null;
}
}