简体   繁体   中英

Error when trying to take screenshot with flutter RenderRepaintBoundary

RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject() 
                                  as RenderRepaintBoundary;

var image = await boundary.toImage(pixelRatio: pixelRatio);

boundary.toImage(pixelRatio: pixelRatio); ## throws error

[ERROR:flutter/shell/common/shell.cc(242)] Dart Unhandled Exception: NoSuchMethodError: The getter '_handles' was called on null.

Receiver: null
Tried calling: _handles, stack trace: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
: #1      new Image._ (dart:ui/painting.dart:1601:12)
: #2      Scene.toImage.<anonymous closure>.<anonymous closure> (dart:ui/compositing.dart:35:24)

It was working fine two weeks ago but now it's throwing this error. How can I fix it?

So basically you have the problem is in boundary.toImage(pixelRatio: pixelRatio);

change it to boundary.toImage();

and it will work fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM