断言失败:第 3379 行第 12 行:'!debugNeedsPaint':不是 true。我收到错误?

问题描述 投票:0回答:1
Future<ui.Image> toImage({ double pixelRatio = 1.0 }) {
    assert(!debugNeedsPaint);
    final OffsetLayer offsetLayer = layer! as OffsetLayer;
    return offsetLayer.toImage(Offset.zero & size, pixelRatio: pixelRatio);
  }

我收到错误消息? 这是控制台中的错误 package:flutter/src/rendering/proxy_box.dart': 断言失败: 第 3379 行 pos 12: '!debugNeedsPaint': 不正确。

我尝试了各种方法,但没有成功。

flutter dart debugging pixel dart-html
1个回答
0
投票

你可以尝试一下这个方法。您的代码的问题是它无法使用扩展名 .toImage() 重新渲染图像。 我希望这会起作用。

Future<void> _capturePng() {
return new Future.delayed(const Duration(milliseconds: 20), () async {
  RenderRepaintBoundary boundary =
      globalKey.currentContext.findRenderObject();
  ui.Image image = await boundary.toImage();
  ByteData byteData =
      await image.toByteData(format: ui.ImageByteFormat.png);
  Uint8List pngBytes = byteData.buffer.asUint8List();
  print(pngBytes);
});

}

© www.soinside.com 2019 - 2024. All rights reserved.