Skip to content

Commit 5870540

Browse files
author
Jonah Williams
authored
[framework] work around to load self packages from packages/ (flutter#111350) (flutter#111410)
1 parent 4f9d92f commit 5870540

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

dev/bots/test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ Future<void> _runFrameworkTests() async {
882882
await _dartRunTest(path.join(flutterRoot, 'dev', 'conductor', 'core'), forceSingleCore: true);
883883
// TODO(gspencergoog): Remove the exception for fatalWarnings once https://github.com/flutter/flutter/pull/91127 has landed.
884884
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing'), fatalWarnings: false);
885+
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'ui'));
885886
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'));
886887
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool'));
887888
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'gen_defaults'));

dev/integration_tests/ui/assets/foo.png

Loading

dev/integration_tests/ui/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,7 @@ dev_dependencies:
7979

8080
flutter:
8181
uses-material-design: true
82+
assets:
83+
- assets/foo.png
8284

8385
# PUBSPEC CHECKSUM: 3ed8
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
9+
// Regression test for https://github.com/flutter/flutter/issues/111285
10+
void main() {
11+
testWidgets('Can load asset from same package without error', (WidgetTester tester) async {
12+
await tester.pumpWidget(MaterialApp(home: Scaffold(body: Image.asset('assets/foo.png', package: 'integration_ui'))));
13+
await tester.pumpAndSettle();
14+
15+
// If this asset couldn't be loaded, the exception message would be
16+
// "asset failed to load"
17+
expect(tester.takeException().toString(), contains('Invalid image data'));
18+
});
19+
}

packages/flutter/lib/src/services/asset_bundle.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,22 @@ class PlatformAssetBundle extends CachingAssetBundle {
266266
final ByteData bytes = await load(key);
267267
return ui.ImmutableBuffer.fromUint8List(bytes.buffer.asUint8List());
268268
}
269+
bool debugUsePlatformChannel = false;
270+
assert(() {
271+
// dart:io is safe to use here since we early return for web
272+
// above. If that code is changed, this needs to be gaurded on
273+
// web presence. Override how assets are loaded in tests so that
274+
// the old loader behavior that allows tests to load assets from
275+
// the current package using the package prefix.
276+
if (Platform.environment.containsKey('UNIT_TEST_ASSETS')) {
277+
debugUsePlatformChannel = true;
278+
}
279+
return true;
280+
}());
281+
if (debugUsePlatformChannel) {
282+
final ByteData bytes = await load(key);
283+
return ui.ImmutableBuffer.fromUint8List(bytes.buffer.asUint8List());
284+
}
269285
try {
270286
return await ui.ImmutableBuffer.fromAsset(key);
271287
} on Exception {

0 commit comments

Comments
 (0)