我们的结构如下:
project A (hosted on private git). It has it's asset folder and is loading assets like this: Image.asset("images/Logo_png_1080x1080px.png")
project B, that uses project A as dependency项目A是一个可以创建ios和android应用程序的应用程序。它充分发挥作用,一切都如预期的那样工作。
现在我们遇到的问题是B项目。
项目B包含简单的初学者类,它设置项目A正在使用的一些基本属性,并且一旦我们成功地正确执行它,就会设置它自己的图标。它还将生产ios和android应用程序。
当我们启动应用程序时,没有任何资产(图像)被识别,我们也有例外:
I/flutter ( 7290):
Unable to load asset: images/Logo_png_1080x1080px.png
I/flutter ( 7290):
I/flutter ( 7290):
When the exception was thrown, this was the stack:
I/flutter ( 7290): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224:7)
I/flutter ( 7290): <asynchronous suspension>
I/flutter ( 7290): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:675:14)
I/flutter ( 7290): <asynchronous suspension>Pubspec内容:
name: project_b
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
project_a:
git:
url: https://***:***@private.git.repo.com/scm/repo/git/ProjectA
ref: master
path: mobile_app
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
uses-material-design: true
# assets:
# - packages/project_a/images/通常,如果依赖有它自己的资产,它应该自己处理它们。但是因为我们必须使用git项目,所以它可能有点不同,因为它不是单独的包,而是与当前的项目(项目B)一起编译的。这就是它找不到资产的原因。
解决这个问题的最好和最正确的方法是什么?谢谢!
发布于 2022-04-05 10:58:38
1-在颤振包中的同样级别的lib文件夹中创建资产文件夹,并将您的字体或图像放在中。

2-在pubspec.yaml中添加资产路径

3-当您想要创建小部件时设置包名

发布于 2022-01-27 11:06:30
我不知道两个集成项目是如何工作的,因此,如果这是一个愚蠢的响应,我提前道歉,但是您是否知道,pubspec.yaml中的资产依赖项(最后两行)被注释掉了。
发布于 2022-01-27 11:35:18
// you are not correctly defining the assets seen in your code under flutter uses-material-design: true assets folder should be like this
uses-material-design: true
assets:
- packages/project_a/images/
if You do not use the proper format you will get an error, Thanks this will help you out. I am sharing my project pubsec.yml file check this
/////pubsec.yml file
name: traveling
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_launcher_icons: ^0.9.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_icons:
image_path: "assets/Vector-2.png"
android: "launcher_icon"
ios: true
remove_alpha_ios: true
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- assets/
- assets/Vector-2.png
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packageshttps://stackoverflow.com/questions/70876849
复制相似问题