简体   繁体   中英

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.

@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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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