简体   繁体   中英

Why Flutter can't find the new API toImageSync for RenderRepaintBoundary class?

The method 'toImageSync' was recently added to Flutter for RenderRepaintBoundary . As shown in this link.

https://api.flutter.dev/flutter/rendering/RenderRepaintBoundary/toImageSync.html

However, it gives me the following error when I try to use it. It works fine if I switch to 'toImage()'. I'm running the latest stable 3.3.10 version.

**The method 'toImageSync' isn't defined for the class 'RenderRepaintBoundary'.**

final boundary =
        key.currentContext!.findRenderObject() as RenderRepaintBoundary;
ui.Image image = boundary.toImageSync();

I don't know why the latest stable 3.3.10 version doesn't recognize toImageSync , but to make it work I simpy updated my flutter to the nearest beta version.

  1. Make sure your flutter path is the same as you use in android studio

  2. Upgrade to beta:

flutter channel beta
flutter upgrade
flutter -version
  1. Set the minimum flutter version in your pubspec.yaml to your installed version:
environment:
  sdk: '>=2.18.6 <3.0.0'
  flutter: '>=3.7.0-1.4.pre'

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