mercredi 27 janvier 2021

The following assertion was thrown while resolving an image: Unable to load asset: AssetManifest.json

So, I made a pub.dev flutter package which uses an image asset.

class GoogleIcon extends StatelessWidget {
  final bool isEnabled;

  const GoogleIcon({
    Key key = const Key('google-icon'),
    this.isEnabled = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: isEnabled ? 1 : 0.5,
      child: Image.asset(
        'assets/google.png',
        key: Key('google-icon-image'),
        package: 'arculus_auth_widgets',
      ),
    );
  }
}

In that library, each of the widget tests run as expected. But when I tried to use the widget in the test of my other package (which depends on it) like this:

  testWidgets('should show buttons at the bottom', (tester) async {
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: ArculusOnboardingBody(
            buttons: [
              ArculusGoogleButton(label: 'Continue with Google'), // This widget contains GoogleIcon in it
            ],
          ),
        ),
      ),
    );

    await tester.pumpAndSettle(Duration(milliseconds: 100));
  });

It failed with

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following assertion was thrown while resolving an image: Unable to load asset: AssetManifest.json

When the exception was thrown, this was the stack: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:225:7) #1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:68:33) #2 CachingAssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:167:18) #3 CachingAssetBundle.loadStructuredData (package:flutter/src/services/asset_bundle.dart:188:5) #4 AssetImage.obtainKey (package:flutter/src/painting/image_resolution.dart:176:18) #5 ScrollAwareImageProvider.obtainKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:115:74) #6 ImageProvider._createErrorHandlerAndKey. (package:flutter/src/painting/image_provider.dart:455:15) #10 ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:452:16) #11 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:330:5) #12 _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1156:16) #13 _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:1109:5) #14 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4786:12) #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) ... Normal element mounting (16 frames) #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) #32 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) ... Normal element mounting (223 frames) #255 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) #256 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) ... Normal element mounting (37 frames) #293 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) #294 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) ... Normal element mounting (202 frames) #496 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) #497 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) ... Normal element mounting (267 frames) #764 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) #765 Element.updateChild (package:flutter/src/widgets/framework.dart:3324:20) #766 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1252:16) #767 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1230:5) #768 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1244:7) #769 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) #770 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33) #771 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1088:18) #772 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5) #773 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15) #774 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9) #775 AutomatedTestWidgetsFlutterBinding.pump. (package:flutter_test/src/binding.dart:961:9) #778 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41) #779 AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:948:27) #780 WidgetTester.pumpWidget. (package:flutter_test/src/widget_tester.dart:524:22) #783 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41) #784 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:521:27) #785 main. (file:///Users/moseskarunia/Projects/arculus/test/src/widgets/arculus_onboarding_body_test.dart:67:18) #786 main. (file:///Users/moseskarunia/Projects/arculus/test/src/widgets/arculus_onboarding_body_test.dart:66:52) #787 testWidgets.. (package:flutter_test/src/widget_tester.dart:146:29) #798 FakeAsync.flushMicrotasks (package:fake_async/fake_async.dart:193:32) #799 AutomatedTestWidgetsFlutterBinding.runTest. (package:flutter_test/src/binding.dart:1189:17) #800 AutomatedTestWidgetsFlutterBinding.runTest. (package:flutter_test/src/binding.dart:1177:35) (elided 32 frames from dart:async and package:stack_trace)

Image provider: ScrollAwareImageProvider() Image configuration: ImageConfiguration(bundle: PlatformAssetBundle#2377c(), devicePixelRatio: 3.0, locale: en_US, textDirection: TextDirection.ltr, platform: android) ════════════════════════════════════════════════════════════════════════════════════════════════════ Test failed. See exception logs above. The test description was: should show buttons at the bottom

✖ should show buttons at the bottom Exited (1)

Do you know where did I do it wrong? It behaves correctly in the actual run though (outside of the test)

Thanks.

Aucun commentaire:

Enregistrer un commentaire