Skip to content

Exception: Invalid image data on preCacheImages #1100

Open

Description

@Crdzbird

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...

Activity

  1. Crdzbird commented on Sep 25, 2024

    @Crdzbird
    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,
            ),
          ));
  2. changed the title [-]Exception: Invalid image data[/-] [+]Exception: Invalid image data on preCacheImages[/+] on Sep 26, 2024
  3. rlee1990 commented on Apr 12, 2025

    @rlee1990

    Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions