|
|
|
@ -27,15 +27,43 @@ abstract class NeonCachedImage extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
Widget build(final BuildContext context) => Center( |
|
|
|
|
child: FutureBuilder<File>( |
|
|
|
|
future: future, |
|
|
|
|
child: FutureBuilder<Uint8List>( |
|
|
|
|
future: _future, |
|
|
|
|
builder: (final context, final fileSnapshot) { |
|
|
|
|
if (fileSnapshot.hasData) { |
|
|
|
|
final content = fileSnapshot.requireData.readAsBytesSync(); |
|
|
|
|
if (!fileSnapshot.hasData) { |
|
|
|
|
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 { |
|
|
|
|
// TODO: Is this safe enough? |
|
|
|
@ -59,27 +87,6 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
|
|
|
|
|
fit: widget.fit, |
|
|
|
|
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, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|