Browse Source

fix(neon): Fix NeonCachedImage BoxFit

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/943/head
jld3103 1 year ago
parent
commit
f611ac82e7
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 74
      packages/neon/neon/lib/src/widgets/image.dart

74
packages/neon/neon/lib/src/widgets/image.dart

@ -135,48 +135,46 @@ class NeonCachedImage extends StatefulWidget {
class _NeonCachedImageState extends State<NeonCachedImage> { class _NeonCachedImageState extends State<NeonCachedImage> {
@override @override
Widget build(final BuildContext context) => Center( Widget build(final BuildContext context) => FutureBuilder(
child: FutureBuilder( future: widget.image,
future: widget.image, builder: (final context, final fileSnapshot) {
builder: (final context, final fileSnapshot) { if (fileSnapshot.hasError) {
if (fileSnapshot.hasError) { return _buildError(fileSnapshot.error);
return _buildError(fileSnapshot.error); }
}
if (!fileSnapshot.hasData) {
return SizedBox(
width: widget.size?.width,
child: const NeonLinearProgressIndicator(),
);
}
if (!fileSnapshot.hasData) { final content = fileSnapshot.requireData;
return SizedBox(
try {
// TODO: Is this safe enough?
if (widget.isSvgHint || utf8.decode(content).contains('<svg')) {
return SvgPicture.memory(
content,
height: widget.size?.height,
width: widget.size?.width, width: widget.size?.width,
child: const NeonLinearProgressIndicator(), fit: widget.fit ?? BoxFit.contain,
colorFilter: widget.svgColorFilter,
); );
} }
} catch (_) {
final content = fileSnapshot.requireData; // If the data is not UTF-8
}
try {
// TODO: Is this safe enough? return Image.memory(
if (widget.isSvgHint || utf8.decode(content).contains('<svg')) { content,
return SvgPicture.memory( height: widget.size?.height,
content, width: widget.size?.width,
height: widget.size?.height, fit: widget.fit,
width: widget.size?.width, gaplessPlayback: true,
fit: widget.fit ?? BoxFit.contain, errorBuilder: (final context, final error, final stacktrace) => _buildError(error),
colorFilter: widget.svgColorFilter, );
); },
}
} catch (_) {
// If the data is not UTF-8
}
return Image.memory(
content,
height: widget.size?.height,
width: widget.size?.width,
fit: widget.fit,
gaplessPlayback: true,
errorBuilder: (final context, final error, final stacktrace) => _buildError(error),
);
},
),
); );
Widget _buildError(final Object? error) => Widget _buildError(final Object? error) =>

Loading…
Cancel
Save