在抖动中传递资产图像时显示错误

法赞汗

我只是一个初学者。我正在尝试将资产图片传递给其他班级,但出现错误。这是我的代码

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");
                         ],
                       ),
                     ),
                   );
                 }
               }

Listinfo类

     class ListInfo
     {
     final String photo;
     final String name;
     ListInfo({this.photo, this.name});
     }

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),
            ),
          ],
        ),
      ),
    );
  }
}

很抱歉提出这样一个基本问题。但我无法解决这个问题

rcvaram

添加资产 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),
        ),
      ],
    ),
  ),
);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从抖动中获取资产时出现ImageIcon颜色问题

如何在抖动中显示全屏图像

抖动图像未显示

渲染部分并将其传递给对象时,如何将资产中的图像显示为背景图像

如何在抖动中显示和更新多个图像

SVG图像不显示抖动

尝试从Rails 5.2中的ActiveStorage显示图像时出现错误

在Xcode中预览不显示资产库中的图像

如何在Today Extension中显示资产目录中的图像?

加载图像时 UITableViewCell 显示错误的图像

ChartJS悬停时显示抖动

尝试显示资产文件夹中的图像

无法在 pubspec 文件中的 Flutter 错误中加载图像资产

在PHP中显示图像错误

尝试在React JS中显示上传的图像的预览时出现图像为空的错误

WatchKit的界面图像中显示了错误的图像

从资产加载图像时出错

蓝色圆圈显示在 CircleAvatar 资产图像中,而不是颤动中的真实图像

加载图像时 RecyclerView 抖动。为什么?

显示图像时出现奇怪的错误

如何在抖动中显示带有顶部和底部渐变阴影的图像?

使用path_provider保存的抖动图像和视频未显示在图库中

Android Studio在文件夹midmap-xxxhdpi中自动创建了图像资产,但是图标名称显示为红色(=错误/未添加?)

如何通过imageprovider类型传递图像资产?

尝试在 Wordpress 中显示自定义文件夹中的图像时出现 404 错误

部署到Web服务器时未显示Flutter Web资产图像

在将Flutter应用迁移到Flutter Web时如何显示图像资产?

图片的异常行为。处理图像时显示错误的图像

如何去抖动/延迟在vee-validate中显示错误消息