未显示颤动图像

时间:2021-04-23 18:58:41

标签: flutter dart flutter-image

所以我正在尝试制作一个带有图像背景的页面,这是我的代码:

body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("loginBackground"),
          ),
        )
      ),

但是,当我运行它时,它会打开一个带有一些 Flutters 代码的新编辑器,并且一行突出显示为黄色,我认为这意味着一个断点(如果我错了,请纠正我)。文件名是“image_provider.dart”,这是相关代码(我已经指出了突出显示的行):

@protected
  Future<ui.Codec> _loadAsync(AssetBundleImageKey key, DecoderCallback decode) async {
    ByteData? data;
    // Hot reload/restart could change whether an asset bundle or key in a
    // bundle are available, or if it is a network backed bundle.
    try {
      data = await key.bundle.load(key.name);
    } on FlutterError {
      PaintingBinding.instance!.imageCache!.evict(key);


      rethrow;          // THIS IS THE HIGHLIGHTED LINE

    }
    // `key.bundle.load` has a non-nullable return type, but might be null when
    // running with weak checking, so we need to null check it anyway (and
    // ignore the warning that the null-handling logic is dead code).
    if (data == null) { // ignore: dead_code
      PaintingBinding.instance!.imageCache!.evict(key);
      throw StateError('Unable to read data');
    }
    return await decode(data.buffer.asUint8List());
  }
}

我不知道这是什么意思,所以任何帮助将不胜感激。 这是图像(滚动):

(抱歉太大了) 如果您需要更多详细信息,请发表评论:)

1 个答案:

答案 0 :(得分:1)

assetImage 中,synatx 通常是这样的:

image: AssetImage("images/loginBackground.png")

此外,如果您没有在 pubspec.yaml 中通过在您的资产部分执行此操作来启用您的资产:

 assets:
    - images/

还有一点错误代码会有所帮助