|
|
@ -27,15 +27,43 @@ abstract class NeonCachedImage extends StatefulWidget { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class _NeonCachedImageState extends State<NeonCachedImage> { |
|
|
|
class _NeonCachedImageState extends State<NeonCachedImage> { |
|
|
|
late Future<File> future = widget.getImageFile(); |
|
|
|
Future<Uint8List> _readImage() async { |
|
|
|
|
|
|
|
final file = await widget.getImageFile(); |
|
|
|
|
|
|
|
return file.readAsBytes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
late Future<Uint8List> _future = _readImage(); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(final BuildContext context) => Center( |
|
|
|
Widget build(final BuildContext context) => Center( |
|
|
|
child: FutureBuilder<File>( |
|
|
|
child: FutureBuilder<Uint8List>( |
|
|
|
future: future, |
|
|
|
future: _future, |
|
|
|
builder: (final context, final fileSnapshot) { |
|
|
|
builder: (final context, final fileSnapshot) { |
|
|
|
if (fileSnapshot.hasData) { |
|
|
|
if (!fileSnapshot.hasData) { |
|
|
|
final content = fileSnapshot.requireData.readAsBytesSync(); |
|
|
|
return SizedBox( |
|
|
|
|
|
|
|
width: widget.size?.width, |
|
|
|
|
|
|
|
child: NeonLinearProgressIndicator( |
|
|
|
|
|
|
|
color: widget.iconColor, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fileSnapshot.hasError) { |
|
|
|
|
|
|
|
return NeonException( |
|
|
|
|
|
|
|
fileSnapshot.error, |
|
|
|
|
|
|
|
onRetry: () { |
|
|
|
|
|
|
|
setState(() { |
|
|
|
|
|
|
|
// ignore: discarded_futures |
|
|
|
|
|
|
|
_future = _readImage(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
onlyIcon: true, |
|
|
|
|
|
|
|
iconSize: widget.size?.shortestSide, |
|
|
|
|
|
|
|
color: widget.iconColor ?? Theme.of(context).colorScheme.error, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final content = fileSnapshot.requireData; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
// TODO: Is this safe enough? |
|
|
|
// TODO: Is this safe enough? |
|
|
@ -59,27 +87,6 @@ class _NeonCachedImageState extends State<NeonCachedImage> { |
|
|
|
fit: widget.fit, |
|
|
|
fit: widget.fit, |
|
|
|
gaplessPlayback: true, |
|
|
|
gaplessPlayback: true, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (fileSnapshot.hasError) { |
|
|
|
|
|
|
|
return NeonException( |
|
|
|
|
|
|
|
fileSnapshot.error, |
|
|
|
|
|
|
|
onRetry: () { |
|
|
|
|
|
|
|
setState(() { |
|
|
|
|
|
|
|
// ignore: discarded_futures |
|
|
|
|
|
|
|
future = widget.getImageFile(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
onlyIcon: true, |
|
|
|
|
|
|
|
iconSize: widget.size?.shortestSide, |
|
|
|
|
|
|
|
color: widget.iconColor ?? Theme.of(context).colorScheme.error, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return SizedBox( |
|
|
|
|
|
|
|
width: widget.size?.width, |
|
|
|
|
|
|
|
child: NeonLinearProgressIndicator( |
|
|
|
|
|
|
|
color: widget.iconColor, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|