Closed dmasotti closed 1 year ago
I couldn't reproduce this issue. Monarch loads images as expected using Image.asset
with the package
property set.
Widget monarch_purple() => Center(
child: Column(children: [
SizedBox(
width: 350,
child: Image.asset('assets/monarch_purple.png',
package: 'scratch_image_core'),
),
]));
I created a repo so you can see the code I used. Could you use that repo to reproduce the issue you are experiencing? I gave you write access.
I 've done an example that explain the problem. This simple app loads an image in the emulator, but raise the error on monarch :
https://www.dropbox.com/s/eomdyxbp0zdcuv1/test_monarch.zip?dl=0
the problem appears when the image is an asset of a dependecy
I got it to work using your code. I think the issue was the following:
example
is a flutter projecttest_monarch
is a dependency of example
test_monarch
has story sample_app_stories.dart
which is importing main.dart
from the example
project via import ../example/lib/main.dart';
. This import creates a cyclical dependency.Instead, I think you want the example
project to have its own stories. If you do that, then the example stories can use example widgets without creating any cyclical dependencies. And then you can load asset images from the test_monarch
project using Monarch.
See this PR.
Using Image.access with not null package results in an error (the app is working with no problem in both ios and android)
...... .... child: Image.asset('assets/images/offlineimg.png',color: Colors.red.withAlpha(200), width:10, height: 10, package: "rhd_core") .......
Image provider: AssetImage(bundle: null, name: "packages/rhd_core/assets/images/rhd_icon.png") Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#5ad87(), name: "packages/rhd_core/assets/images/rhd_icon.png", scale: 1.0) ════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following assertion was thrown resolving an image codec: Unable to load asset: "packages/rhd_core/assets/images/offlineimg.png". Exception: Asset not found
The relevant story is: stories/rhd_view_stories.dart > primary
When the exception was thrown, this was the stack:
0 PlatformAssetBundle.loadBuffer (package:flutter/src/services/asset_bundle.dart:295:7)
1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:731:35)
2 AssetBundleImageProvider.loadBuffer (package:flutter/src/painting/image_provider.dart:695:14)
3 ImageProvider.resolveStreamForKey. (package:flutter/src/painting/image_provider.dart:513:13)
4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:384:22)
5 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:511:81)
6 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:106:19)
7 ImageProvider.resolve. (package:flutter/src/painting/image_provider.dart:358:9)
8 ImageProvider._createErrorHandlerAndKey. (package:flutter/src/painting/image_provider.dart:473:24)