相关疑难解决方法(0)

FlutterError:无法加载资产

这是我的应用程序的文件夹结构

.idea
.vscode
android
build
fonts
 Oxygen-Bold.tff
 Oxygen-Light.tff
 Oxygen-Regular.tff
images
 pizza0.png
 pizza1.png
ios
lib
 ui
  home.dart
 main.dart
test
.gitignore
.metadata
.packages
app_widgets.iml
pubspec.lock
pubspec.yaml
README.md
Run Code Online (Sandbox Code Playgroud)

在我的pubspec.yaml文件中,我像这样加载字体和素材资源

flutter:

uses-material-design: true

assets:
  - images/pizza0.png
  - images/pizza1.png

fonts:
  - family: Oxygen
    fonts:
      - asset: fonts/Oxygen-Regular.ttf
      - asset: fonts/Oxygen-Bold.ttf
        weight: 700
      - asset: fonts/Oxygen-Light.ttf
        weight: 300
Run Code Online (Sandbox Code Playgroud)

我没有收到此yaml文件的任何错误,并且运行“ flutter package get”给出的退出代码为0。

在我的home.dart中,我有以下课程:

class PizzaImageWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    AssetImage pizzaAsset = AssetImage('images/pizza0.png');
    Image image = Image(image: pizzaAsset, width: 400, height: 400); …
Run Code Online (Sandbox Code Playgroud)

assets flutter

18
推荐指数
16
解决办法
2万
查看次数

未加载颤动图像(例外:解析图像编解码器)

当我尝试运行图像资产没有正确加载时,我得到一个例外:

抛出以下断言解析图像编解码器:无法加载资产:/ images/p8.png`

几周前它正在运作,现在它停止了.我试图从不同的PC和Mac运行(使用模拟器),但仍然无法加载图像.而是正确加载字体.

这是我加载图像的方式,它们是在里面呈现的,GridView 下面是代码:

return new Expanded(
      child: new GridView.count(
          crossAxisCount: 2,
          padding: const EdgeInsets.fromLTRB(16.0, 25.0, 16.0, 4.0),
          children: <Widget>[
            new MaterialButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/biliardo');
              },
              child: new Column(
                children: <Widget>[
                  new Image(
                    //parte importante, definire gli asset per trovarli più velocemnte
                    //si inseriscono nel pubspec.yaml
                    image: new AssetImage('/images/p8.png'),
                    height: 100.0,
                    width: 100.0,
                  ),
                  new Text(
                    "BILIARDO",
                    style: new TextStyle(
                      color: (darkTheme) ? Colors.blue : Colors.black,
                    ),
                  )
                ],
              ),
            ),

            .....

    );
Run Code Online (Sandbox Code Playgroud)

pubsec.yaml文件代码:

flutter:
  uses-material-design: …
Run Code Online (Sandbox Code Playgroud)

image codec dart flutter

10
推荐指数
5
解决办法
1万
查看次数

标签 统计

flutter ×2

assets ×1

codec ×1

dart ×1

image ×1