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,我只是一个新手。我试图将资产图像传递给其他类,但出现错误。 这是我的密码 main.dart文件 class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( t

我只是一个新手。我试图将资产图像传递给其他类,但出现错误。 这是我的密码

main.dart文件

        
     class MyApp extends StatelessWidget {
       @override
        Widget build(BuildContext context) {
        return MaterialApp(
        home: Scaffold(
        appBar: AppBar(
          title: Text('Home'),
        ),
        body: ListView(
          children: <Widget>[
             ListInfo(photo:"assets\images\apple.jpg",name:"Apple");
                         ],
                       ),
                     ),
                   );
                 }
               }
ListImages类

        class ListImages extends StatelessWidget {
        @override
         ListInfo info = new ListInfo();
        Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(20.0),
      child: Center(
        child: Column(
          children: <Widget>[
            Image(
              image: AssetImage(info.photo),
            ),
            Text(
              info.name,
              style: TextStyle(fontSize: 30.0),
            ),
          ],
        ),
      ),
    );
  }
}
类ListImages扩展了无状态小部件{
@凌驾
ListInfo info=新ListInfo();
小部件构建(构建上下文){
返回容器(
填充:所有边缘设置(20.0),
儿童:中心(
子:列(
儿童:[
形象(
图片:AssetImage(信息图片),
),
正文(
info.name,
样式:TextStyle(fontSize:30.0),
),
],
),
),
);
}
}

很抱歉问了这么一个基本的问题。但是我无法解决这个问题

pubspec.yaml

# To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

 assets:
  -assets\images\apple.jpg
  -assets\images\orange.jpg
然后使用
pub-get

使用
Image.asset('assets\images\apple.jpg')
将图像作为小部件添加到列表中

return Container(
  padding: EdgeInsets.all(20.0),
  child: Center(
    child: Column(
      children: <Widget>[
        Image.asset('assets\images\apple.jpg',),
        Text(
          info.name,
          style: TextStyle(fontSize: 30.0),
        ),

        Image.asset('assets\images\orange.jpg',),
        Text(
          info.name,
          style: TextStyle(fontSize: 30.0),
        ),
      ],
    ),
  ),
);
返回容器(
填充:所有边缘设置(20.0),
儿童:中心(
子:列(
儿童:[
Image.asset('assets\images\apple.jpg',),
正文(
info.name,
样式:TextStyle(fontSize:30.0),
),
Image.asset('assets\images\orange.jpg',),
正文(
info.name,
样式:TextStyle(fontSize:30.0),
),
],
),
),
);

pubspec.yaml

# To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

 assets:
  -assets\images\apple.jpg
  -assets\images\orange.jpg
然后使用
pub-get

使用
Image.asset('assets\images\apple.jpg')
将图像作为小部件添加到列表中

return Container(
  padding: EdgeInsets.all(20.0),
  child: Center(
    child: Column(
      children: <Widget>[
        Image.asset('assets\images\apple.jpg',),
        Text(
          info.name,
          style: TextStyle(fontSize: 30.0),
        ),

        Image.asset('assets\images\orange.jpg',),
        Text(
          info.name,
          style: TextStyle(fontSize: 30.0),
        ),
      ],
    ),
  ),
);
返回容器(
填充:所有边缘设置(20.0),
儿童:中心(
子:列(
儿童:[
Image.asset('assets\images\apple.jpg',),
正文(
info.name,
样式:TextStyle(fontSize:30.0),
),
Image.asset('assets\images\orange.jpg',),
正文(
info.name,
样式:TextStyle(fontSize:30.0),
),
],
),
),
);

您是否有图像列表如果有更多图像,则将其添加到子级中您是否有图像列表如果有更多图像,则将其添加到子级中