Open rignaneseleo opened 4 years ago
I solved using this workaround widget:
import 'dart:typed_data';
import 'dart:ui';
import 'package:photo/photo.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:flutter/material.dart';
import 'package:photo/src/delegate/badge_delegate.dart';
import 'package:photo/src/delegate/loading_delegate.dart';
import 'package:photo/src/engine/lru_cache.dart';
class MyImageItem extends StatefulWidget {
final AssetEntity entity;
final Color themeColor;
final int size;
final LoadingDelegate loadingDelegate;
final BadgeDelegate badgeDelegate;
const MyImageItem({
Key key,
this.entity,
this.themeColor,
this.size = 64,
this.loadingDelegate,
this.badgeDelegate,
}) : super(key: key);
@override
_MyImageItemState createState() => _MyImageItemState();
}
class _MyImageItemState extends State<MyImageItem> {
bool _isInit = false;
Uint8List data;
@override
void initState() {
_load();
super.initState();
}
_load() async {
setState(() {
_isInit = false;
});
try {
data = await widget.entity.thumbDataWithSize(widget.size, widget.size);
} catch (e) {
print("ERROR!!!!!!!!!!");
data= //LOAD HERE A REPLACER
}
setState(() {
_isInit = true;
});
}
@override
Widget build(BuildContext context) {
if (!_isInit)
return Center(
child: widget.loadingDelegate.buildPreviewLoading(
context,
widget.entity,
widget.themeColor,
),
);
var thumb = ImageLruCache.getData(widget.entity, widget.size);
if (thumb != null) {
return _buildImageItem(context, thumb);
}
ImageLruCache.setData(widget.entity, widget.size, data);
return _buildImageItem(context, data);
}
Widget _buildImageItem(BuildContext context, Uint8List data) {
var image = Image.memory(
data,
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
);
var badge;
final badgeBuilder = widget.badgeDelegate
?.buildBadge(context, widget.entity.type, widget.entity.videoDuration);
if (badgeBuilder == null) {
badge = Container();
} else {
badge = badgeBuilder;
}
return Stack(
children: <Widget>[
image,
IgnorePointer(
child: badge,
),
],
);
}
}
Nowadays the HEIC and HEIF contents are not supported from your ImageItem widget that will give an error like this:
I'm wondering if you can let us handle the onError situation so we can manually convert the picture in JPG and display it.
Thanks