简体   繁体   English

为什么 flutter 无法加载资产图像?

[英]Why is flutter unable to load asset image?

No errors in the code and as far as I can see the pubspec.yaml file is functional, as it worked before.代码中没有错误,据我所知,pubspec.yaml 文件可以正常工作,就像以前一样。

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Column(
            children: [
              Card(
                child: Image.asset('anyaparent.jpeg'),
              ),
            ],
          ),
        ),
      ),
    );

错误文本“无法加载资产”

[1]:https://i.stack.imgur.com/GeTW2.png pubspec.yaml 文件

try doing like this尝试这样做

Image.asset('images/anyaparent.jpeg'),

Check your image path images/anyaparent.jpeg检查您的图像path images/anyaparent.jpeg

@override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: SafeArea(
              child: Column(
                children: [
                  Card(
                    child: Image.asset('images/anyaparent.jpeg'),
                  ),
                ],
              ),
            ),
          ),
        );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM