【问题标题】:Image not showing in flutter application图像未在颤振应用程序中显示
【发布时间】:2019-08-01 14:17:02
【问题描述】:

我只是从资产文件夹中加载图像,而图像未显示在应用程序中。但是当我使用网络加载图像时,它会完美加载。 (我使用的是 linux flat form) 这是我的代码

    class Splash extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: Center(
         child: new Image.asset('assets/images/login_logo.png'),
//Image.network('https://mobile-di.com/wp-content/uploads/2018/08/flutter-review.jpeg'), //this works
          ),
        );
      }
      }

在 pubspec.yaml 文件中

assets:
  - assets/images/login_logo.png

【问题讨论】:

  • 控制台输出有错误吗?
  • 没有发现任何错误

标签: image flutter assets


【解决方案1】:

确保您在pubspec.yaml 中的flutter: 下添加资产。另外,检查您是否在资产之前添加空格。在您的示例中,请检查该资产的路径是否存在。并确保您的项目文件夹中有该名称的资产。 示例:

flutter:
  assets:
  - lib/img_package/example.png

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 2020-11-15
    • 2020-10-10
    • 2022-10-09
    • 2020-09-03
    • 2021-10-13
    • 2021-03-05
    相关资源
    最近更新 更多