首页 > 解决方案 > 无法在颤动中加载资产(图像)

问题描述

这就是代码(应用程序)的样子。

Aight people 这是我第一次这样做,所以我会尽量做到精确和整洁......

所以我刚刚开始学习颤振,我正在观看关于它的课程,但是在复制教练输入的内容时,每当我尝试在我的虚拟或物理设备上运行此代码时,我偶然发现了这个问题,它不会加载图片。我检查了 pubsec.yaml 文件,一切似乎都工作正常,但图像没有加载。顺便说一句,我正在使用最新版本的 AndroidStudio(我猜是金丝雀)。在此先感谢,我希望有人能帮助我。这是代码:

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.blueGrey,
        appBar: AppBar(
          title: Center(
            child: Text('I am rich.'),
          ),
          backgroundColor: Colors.blueGrey[900],
        ),
        body: Center(
          child: Image(
            image: AssetImage('diamond.png'),
          ),
        ),
      ),
    ),
  );
}

这是代码中图片的下载链接: https ://drive.google.com/uc?export=download&id=1IA7othwL6jGtvc1Wfyj0K6hxrEH9OHam

标签: androidflutter

解决方案


您是否将图像的路径放在pubspec.yaml? 为了让 Flutter 识别你的资产图片,你需要把他的路径放在pubspec.yaml你的项目文件中。


推荐阅读