Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: Invalid image data on preCacheImages #1100

Open
Crdzbird opened this issue Sep 25, 2024 · 1 comment
Open

Exception: Invalid image data on preCacheImages #1100

Crdzbird opened this issue Sep 25, 2024 · 1 comment

Comments

@Crdzbird
Copy link

Hi. I was using the precacheImage built-in function, however im facing some issues.

im using an extension to cache every svg available.

extension BuildContextExtension on BuildContext {

  Future<void> preCacheSVGs() => Future.wait(
        SvgEnum.values.map(
          (SvgEnum svg) => precacheImage(
            AssetImage(
              svg.path,
            ),
            this,
            onError: (e, stackTrace) {
              debugPrint('Error: $e');
              debugPrint('Stack Trace: $stackTrace');
            },
          ),
        ),
      );
}

however when I call it directly from my splash sub-widget I keep receiving
flutter: Error: Exception: Invalid image data flutter: Stack Trace: #0 _futurize (dart:ui/painting.dart:7021:5) flutter: #1 ImageDescriptor.encoded (dart:ui/painting.dart:6827:12) flutter: #2 instantiateImageCodecWithSize (dart:ui/painting.dart:2306:60) flutter: #3 PaintingBinding.instantiateImageCodecWithSize (package:flutter/src/painting/binding.dart:146:15) flutter: #4 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:762:18) flutter: <asynchronous suspension> flutter: #5 MultiFrameImageStreamCompleter._handleCodecReady (package:flutter/src/painting/image_stream.dart:1013:3) flutter: <asynchronous suspension> flutter: flutter: Error: Exception: Invalid image data flutter: Stack Trace: #0 _futurize (dart:ui/painting.dart:7021:5) flutter: #1 ImageDescriptor.encoded (dart:ui/painting.dart:6827:12) flutter: #2 instantiateImageCodecWithSize (dart:ui/painting.dart:2306:60) flutter: #3 PaintingBinding.instantiateImageCodecWithSize (package:flutter/src/painting/binding.dart:146:15) flutter: #4 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:762:18) flutter: <asynchronous suspension> flutter: #5 MultiFrameImageStreamCompleter._handleCodecReady (package:flutter/src/painting/image_stream.dart:1013:3) flutter: <asynchronous suspension> flutter:

and this is the PreloaderWidget:

class PreloaderWidget extends StatelessWidget {
  const PreloaderWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<void>(
      future: context.preCacheSVGs(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          imageCache.clear();
          WidgetsBinding.instance.addPostFrameCallback(
            (_) => context.router.pushNamed(ScreensEnum.authentication.path),
          );
        }
        return const Center(child: SvgPicture.asset(SvgEnum.devotion.path));
      },
    );
  }
}

this only happens if using the preload, and im not sure how to fix it...

@Crdzbird
Copy link
Author

Doing some tests with previous version: 1.1.6 , it seems that the issue disappears. maybe it's something related to the need of a context for the preload?

  Future<void> preCacheSVGs() async => Future.wait(SvgEnum.values.map(
        (SvgEnum svg) => precachePicture(
          ExactAssetPicture(
            SvgPicture.svgStringDecoderBuilder,
            svg.path,
          ),
          null,
        ),
      ));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant