From de4f2397e139f659f77d47da395117c9ef37d002 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 29 Jun 2023 14:38:02 +0200 Subject: [PATCH] neon: improve loading animation of NeonCachedImage --- .../neon/lib/src/widgets/cached_image.dart | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index 43d0331a..3e1fe9b6 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -27,46 +27,34 @@ abstract class NeonCachedImage extends StatefulWidget { } class _NeonCachedImageState extends State { - late Future future = widget.getImageFile(); + Future _readImage() async { + final file = await widget.getImageFile(); + return file.readAsBytes(); + } + + late Future _future = _readImage(); @override Widget build(final BuildContext context) => Center( - child: FutureBuilder( - future: future, + child: FutureBuilder( + future: _future, builder: (final context, final fileSnapshot) { - if (fileSnapshot.hasData) { - final content = fileSnapshot.requireData.readAsBytesSync(); - - try { - // TODO: Is this safe enough? - if (widget.isSvgHint || utf8.decode(content).contains(' { color: widget.iconColor ?? Theme.of(context).colorScheme.error, ); } - return SizedBox( + + final content = fileSnapshot.requireData; + + try { + // TODO: Is this safe enough? + if (widget.isSvgHint || utf8.decode(content).contains('