Skip to content

Exception: Invalid image data on preCacheImages #1100

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

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