Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何解决在颤振中无法加载资产的错误?_Flutter - Fatal编程技术网

Flutter 如何解决在颤振中无法加载资产的错误?

Flutter 如何解决在颤振中无法加载资产的错误?,flutter,Flutter,实际上,我想在我的应用程序中添加图像,但它抛出了一个错误,表示无法加载图像资源。 以下是我尝试过的几种方法: 1) 在pubspec.yaml文件中保持资产的正确缩进,并且没有显示任何错误。 2) 跑——飞得干干净净,但还是一次又一次地犯同样的错误 //pubspec.yaml: //你可以查我的密码 ` import 'package:flutter/material.dart';` void main()=>runApp(MyApp()) classmyapp扩展了无状态小部件{ @覆

实际上,我想在我的应用程序中添加图像,但它抛出了一个错误,表示无法加载图像资源。 以下是我尝试过的几种方法: 1) 在pubspec.yaml文件中保持资产的正确缩进,并且没有显示任何错误。 2) 跑——飞得干干净净,但还是一次又一次地犯同样的错误

//pubspec.yaml:

//你可以查我的密码

` import 'package:flutter/material.dart';`
void main()=>runApp(MyApp())

classmyapp扩展了无状态小部件{

@覆盖

小部件构建(构建上下文){

return MaterialApp(

primarySwatch:Colors.deepPurple,

     `visualDensity: VisualDensity.adaptivePlatformDensity,`
  
),

主页:主页(标题:“颤振布局演示”),

);

}

}

类主页扩展了无状态控件{

主页({Key-Key,this.title}):超级(Key:Key);

最终字符串标题;

@覆盖

小部件构建(构建上下文){

返回脚手架(

appBar:appBar(

标题:文本(“产品列表”),
)`

resizetoavidbottompadding:false,

`body:ListView(`

    `shrinkWrap: true,`

    `padding: const EdgeInsets.fromLTRB(2, 10, 2, 10),`

    `scrollDirection: Axis.vertical,`

    `physics: AlwaysScrollableScrollPhysics(),`

    `children: <Widget>[`

     ` ProductList(`

        `name:"Iphone",`

        `description:"Iphone is the most stylist phone you could ever get" ,`

        `image: "images/iphone.jpg",`

        `price: 200000,`

      `),`

      `ProductList(`

        `name:"Pixel",`

        `description:"Pixel is the most stylist phone you could ever get" ,`

        `image: "images/pixel.jpg",`

        `price: 200000,`

      `),`

      `ProductList(`

        `name:"Tablet",`

        `description:"Tablet is the most versatile and portable phone you could carry" ,`

        `image: "images/tablet.jpg",`

        `price: 50000,`

      `),`

      `ProductList(`

        `name:"Laptop",`

        `description:"Laptop is the most productive development tool" ,`

        `image: "images/laptop.jpg",`

        `price: 560000,`

      `),`

      

    `],`

 ` ),`

`);`
}

}


`

您已经在对象中定义了图像的路径

image: "images/iphone.jpg",
所以,只需改变这一点:

Image.asset("images/"+image),

不客气:如果这个答案解决了你的问题,请考虑接受它。
image: "images/iphone.jpg",
Image.asset("images/"+image),
Image.asset(image),
Image.asset('images/iphone.jpg')