|
|
|
|
|
|
return new ImageConfiguration( |
|
|
|
bundle: DefaultAssetBundle.of(context), |
|
|
|
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0f, |
|
|
|
//locale: Localizations.localeOf(context, nullOk: true),
|
|
|
|
locale: Localizations.localeOf(context, nullOk: true), |
|
|
|
size: size, |
|
|
|
platform: Application.platform |
|
|
|
); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public delegate Widget ImageFrameBuilder ( |
|
|
|
BuildContext context, |
|
|
|
Widget child, |
|
|
|
int frame, |
|
|
|
bool wasSynchronouslyLoaded |
|
|
|
public delegate Widget ImageFrameBuilder( |
|
|
|
BuildContext context, |
|
|
|
Widget child, |
|
|
|
int frame, |
|
|
|
bool wasSynchronouslyLoaded |
|
|
|
|
|
|
|
// [!!!] class ImageChunkEvent is missing
|
|
|
|
|
|
|
|
BuildContext context, |
|
|
|
Widget child//,
|
|
|
|
//ImageChunkEvent loadingProgress
|
|
|
|
BuildContext context, |
|
|
|
Widget child, |
|
|
|
ImageChunkEvent loadingProgress |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Image : StatefulWidget { |
|
|
|
public Image( |
|
|
|
Key key = null, |
|
|
|
|
|
|
bool gaplessPlayback = false, |
|
|
|
FilterQuality filterQuality = FilterQuality.low, |
|
|
|
IDictionary<string, string> headers = null, |
|
|
|
int cacheWidth = default, |
|
|
|
int cacheHeight = default |
|
|
|
int? cacheWidth = null, |
|
|
|
int? cacheHeight = null |
|
|
|
var networkImage = new NetworkImage(src, scale, headers);//image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, NetworkImage(src, scale: scale, headers: headers));
|
|
|
|
var image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, |
|
|
|
new NetworkImage(src, scale: scale, headers: headers)); |
|
|
|
image: networkImage, |
|
|
|
image: image, |
|
|
|
frameBuilder: frameBuilder, |
|
|
|
loadingBuilder: loadingBuilder, |
|
|
|
errorBuilder: errorBuilder, |
|
|
|
|
|
|
Rect centerSlice = null, |
|
|
|
bool gaplessPlayback = false, |
|
|
|
FilterQuality filterQuality = FilterQuality.low, |
|
|
|
int cacheWidth = default, |
|
|
|
int cacheHeight = default |
|
|
|
int? cacheWidth = null, |
|
|
|
int? cacheHeight = null |
|
|
|
|
|
|
|
var fileImage = new FileImage(file, scale);//ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, FileImage(file, scale: scale));
|
|
|
|
var fileImage = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, new FileImage(file, scale: scale)); |
|
|
|
return new Image( |
|
|
|
key: key, |
|
|
|
image: fileImage, |
|
|
|
|
|
|
Rect centerSlice = null, |
|
|
|
bool gaplessPlayback = false, |
|
|
|
FilterQuality filterQuality = FilterQuality.low, |
|
|
|
int cacheWidth = default, |
|
|
|
int cacheHeight = default |
|
|
|
int? cacheWidth = default, |
|
|
|
int? cacheHeight = null |
|
|
|
) { |
|
|
|
/*image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, scale != null |
|
|
|
? ExactAssetImage(name, bundle: bundle, scale: scale, package: package) |
|
|
|
|
|
|
Rect centerSlice = null, |
|
|
|
bool gaplessPlayback = false, |
|
|
|
FilterQuality filterQuality = FilterQuality.low, |
|
|
|
int cacheWidth = default, |
|
|
|
int cacheHeight = default |
|
|
|
int? cacheWidth = default, |
|
|
|
int? cacheHeight = null |
|
|
|
) { |
|
|
|
// ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale));
|
|
|
|
var memoryImage = new MemoryImage(bytes, scale); |
|
|
|
|
|
|
properties.add(new EnumProperty<ImageRepeat>("repeat", repeat, defaultValue: ImageRepeat.noRepeat)); |
|
|
|
properties.add(new DiagnosticsProperty<Rect>("centerSlice", centerSlice, |
|
|
|
defaultValue: foundation_.kNullDefaultValue)); |
|
|
|
properties.add(new EnumProperty<FilterQuality>("filterQuality", filterQuality, foundation_.kNullDefaultValue)); |
|
|
|
properties.add(new EnumProperty<FilterQuality>("filterQuality", filterQuality, |
|
|
|
foundation_.kNullDefaultValue)); |
|
|
|
public class _ImageState : State<Image> ,WidgetsBindingObserver{ |
|
|
|
public class _ImageState : State<Image>, WidgetsBindingObserver { |
|
|
|
|
|
|
|
//ImageChunkEvent _loadingProgress;
|
|
|
|
|
|
|
|
ImageChunkEvent _loadingProgress; |
|
|
|
bool _isListeningToStream = false; |
|
|
|
bool _invertColors; |
|
|
|
int _frameNumber; |
|
|
|
|
|
|
StackTrace _lastStack; |
|
|
|
|
|
|
|
|
|
|
|
public override void initState() { |
|
|
|
base.initState(); |
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
|
|
|
_scrollAwareContext.dispose(); |
|
|
|
base.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override void didChangeDependencies() { |
|
|
|
_updateInvertColors(); |
|
|
|
_resolveImage(); |
|
|
|
|
|
|
Image image = (Image) oldWidget; |
|
|
|
if (_isListeningToStream && |
|
|
|
(widget.loadingBuilder == null) != (image.loadingBuilder == null)) { |
|
|
|
/*_imageStream.removeListener(_getListener(image.loadingBuilder)); |
|
|
|
_imageStream.addListener(_getListener());*/ |
|
|
|
_imageStream.removeListener(_getListener(image.loadingBuilder)); |
|
|
|
_imageStream.addListener(_getListener()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*public override void didChangeAccessibilityFeatures() { |
|
|
|
base.didChangeAccessibilityFeatures(); |
|
|
|
setState(() => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _updateInvertColors() { |
|
|
|
_invertColors = MediaQuery.of(context, nullOk: true)?.invertColors |
|
|
|
?? false; |
|
|
|
|
|
|
D.assert(newStream != null); |
|
|
|
_updateSourceStream(newStream); |
|
|
|
} |
|
|
|
|
|
|
|
/*ImageStreamListener _getListener(ImageLoadingBuilder loadingBuilder = null) { |
|
|
|
loadingBuilder ??= widget.loadingBuilder; |
|
|
|
|
|
|
|
void _onError(Exception error) { |
|
|
|
setState(() => { |
|
|
|
_lastException = error; |
|
|
|
// _lastStack = stackTrace;
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
ImageStreamListener _getListener(ImageLoadingBuilder loadingBuilder = null) { |
|
|
|
loadingBuilder = loadingBuilder ?? widget.loadingBuilder; |
|
|
|
ImageChunkListener onChunk = null; |
|
|
|
if (loadingBuilder == null) { |
|
|
|
onChunk = _handleImageChunk; |
|
|
|
} |
|
|
|
|
|
|
|
ImageErrorListener onError = null; |
|
|
|
if (widget.errorBuilder != null) { |
|
|
|
onError = (Exception error) => { |
|
|
|
setState(() => { |
|
|
|
_lastException = error; |
|
|
|
// _lastStack = stackTrace;
|
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
onChunk: loadingBuilder == null ? null : _handleImageChunk, |
|
|
|
onError: widget.errorBuilder != null |
|
|
|
? (dynamic error, StackTrace stackTrace) => { |
|
|
|
setState(() => { |
|
|
|
_lastException = error; |
|
|
|
_lastStack = stackTrace; |
|
|
|
}); |
|
|
|
} |
|
|
|
: null |
|
|
|
); |
|
|
|
}*/ |
|
|
|
onChunk: onChunk, |
|
|
|
onError: onError |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) { |
|
|
|
setState(() =>{ |
|
|
|
void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) { |
|
|
|
setState(() => { |
|
|
|
_imageInfo = imageInfo; |
|
|
|
_loadingProgress = null; |
|
|
|
_frameNumber = _frameNumber == null ? 0 : _frameNumber + 1; |
|
|
|
|
|
|
|
|
|
|
void _handleImageChunk(ImageChunkEvent _event) { |
|
|
|
D.assert(widget.loadingBuilder != null); |
|
|
|
setState(() => { |
|
|
|
_loadingProgress = _event; |
|
|
|
}); |
|
|
|
}*/ |
|
|
|
setState(() => { _loadingProgress = _event; }); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: update
|
|
|
|
// if (_isListeningToStream) {
|
|
|
|
// _imageStream.removeListener(_handleImageChanged);
|
|
|
|
// }
|
|
|
|
if (_isListeningToStream) { |
|
|
|
_imageStream.removeListener(_getListener()); |
|
|
|
} |
|
|
|
// TODO: update
|
|
|
|
// _imageStream = newStream;
|
|
|
|
// if (_isListeningToStream) {
|
|
|
|
// _imageStream.addListener(_handleImageChanged);
|
|
|
|
// }
|
|
|
|
_imageStream = newStream; |
|
|
|
if (_isListeningToStream) { |
|
|
|
_imageStream.addListener(_getListener()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _listenToStream() { |
|
|
|
|
|
|
|
|
|
|
// TODO: update
|
|
|
|
// _imageStream.addListener(_handleImageChanged);
|
|
|
|
// _isListeningToStream = true;
|
|
|
|
_imageStream.addListener(_getListener()); |
|
|
|
_isListeningToStream = true; |
|
|
|
} |
|
|
|
|
|
|
|
void _stopListeningToStream() { |
|
|
|
|
|
|
|
|
|
|
// TODO: update
|
|
|
|
// _imageStream.removeListener(_handleImageChanged);
|
|
|
|
_imageStream.removeListener(_getListener()); |
|
|
|
|
|
|
|
|
|
|
|
if (_lastException != null) { |
|
|
|
if (_lastException != null) { |
|
|
|
RawImage image = new RawImage( |
|
|
|
|
|
|
|
Widget image = new RawImage( |
|
|
|
image: _imageInfo?.image, |
|
|
|
width: widget.width, |
|
|
|
height: widget.height, |
|
|
|
|
|
|
invertColors: _invertColors, |
|
|
|
filterQuality: widget.filterQuality |
|
|
|
); |
|
|
|
/*if (widget.frameBuilder != null) |
|
|
|
if (widget.frameBuilder != null) |
|
|
|
image = widget.loadingBuilder(context, image, _loadingProgress);*/ |
|
|
|
|
|
|
|
image = widget.loadingBuilder(context, image, _loadingProgress); |
|
|
|
|
|
|
|
return image; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
description.add(new DiagnosticsProperty<bool>("wasSynchronouslyLoaded", _wasSynchronouslyLoaded)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void didChangeMetrics() { |
|
|
|
setState(); |
|
|
|
} |
|
|
|