Skip to content

Asset bundle fails to load assets on tests in specific cases after 3.3.0 #111285

@renancaraujo

Description

@renancaraujo

As a maintainer of a flutter package that may contain references to assets, it is required that inside this package, assets should be loaded with package/<packageName> prefix in its key.

When testing code that loads these assets, we get an error after flutter 3.3.0

Steps to Reproduce

Added a simple code here in the issue and a more complete example here.

  1. Checkout into flutter 3.0.0
  2. Execute flutter test on the code sample or on the example package.
  3. It will pass (as it should).
  4. Checkout into flutter 3.3.0
  5. Execute flutter test on the code sample or on the example package.
  6. It will fail because it cant load the asset.

Expected results:

Tests should pass.

It should be consistent across versions since it was not listed as a breaking change.

Testing widgets with assets in packages can be a real hack if it is not possible to maintain the prefix during tests.

Actual results:

Tests fail.

Code sample
// Package content file: lib/src/anything.dart

import 'package:flutter/widgets.dart';

/// Some Widget with an image
class SomeImageWidget extends StatelessWidget {
  /// Some Widget with an image
  const SomeImageWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Image.asset('packages/asset_bundle_bug/assets/pudim.jpg');
  }
}
// Test file: test/anything_test.dart

void main() {
  group('SomeImageWidget', () {
    testWidgets('can be pumped', (tester) async {
      await tester.pumpWidget(SomeImageWidget());
      await tester.pumpAndSettle();
      expect(true, true);
    });
  });
}


Possible context

This PR may have introduced the bug:
flutter/engine#32999
#103496

Metadata

Metadata

Assignees

Labels

a: assetsPackaging, accessing, or using assetsa: tests"flutter test", flutter_test, or one of our testsc: regressionIt was better in the past than it is nowfound in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions