【问题标题】:Image not being Shown for Flutter AppBarFlutter AppBar 未显示图像
【发布时间】:2020-03-07 19:48:09
【问题描述】:

以下代码的图像未显示,并引发异常。我的 pubspec 正确对齐,所以不确定出了什么问题。

我尝试更新颤振,重新启动,重新对齐,但仍然得到下面相同的异常。

将文件同步到设备 iPhone X...颤动:══╡ 异常捕获 图像资源服务 ╞═════════════════════════════════════════════════ ═══扑: 抛出以下断言解析图像编解码器:颤振: 无法加载资产:/images/barlogo.png 颤振:颤振:当 抛出异常,这是堆栈:颤振:#0
PlatformAssetBundle.load (包:flutter/src/services/asset_bundle.dart:221:7)

import 'package:flutter/material.dart';

void main() {
  return runApp(
      MaterialApp(
          home: Scaffold(
            appBar: AppBar(
              backgroundColor: new Color(0xffA62FF0),
              centerTitle: true,
              elevation: 1.0,
              leading: new Icon(Icons.camera_alt),
              title: SizedBox(
                  height: 35.0, child:new Image.asset('/images/barlogo.png')),
              actions: <Widget>[
                Padding(
                  padding: const EdgeInsets.only(right: 12.0),
                  child: new Image.asset('/images/search.png'),
                )
              ],
            ),
          )
      )
  );
}


【问题讨论】:

    标签: flutter


    【解决方案1】:

    异常给出了它 - Flutter 找不到请求的图像。

    在指定资产路径时,您不应使用前导 /。试试:

    Image.asset('images/barlogo.png')
    

    文档中有更多信息:https://api.flutter.dev/flutter/widgets/Image/Image.asset.html

    【讨论】:

    • 顺便说一句,您知道是否有办法将图像添加为 AppBar 的背景
    • 最好打开一个新问题,提供有关您要实现的目标的更多信息 - 您可以在多个地方将图像放入 AppBar。
    猜你喜欢
    • 1970-01-01
    • 2020-10-26
    • 2019-04-15
    • 2022-06-15
    • 1970-01-01
    • 2020-05-22
    • 2021-05-24
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多