Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugNeedsPaint is not true #35

Closed
mrtungdev opened this issue Mar 2, 2021 · 3 comments
Closed

debugNeedsPaint is not true #35

mrtungdev opened this issue Mar 2, 2021 · 3 comments
Assignees

Comments

@mrtungdev
Copy link

Hello, just implemented this package, when I call:

final captureImage = await screenshotController.captureAsUiImage(pixelRatio: 2);
final data = await captureImage.toByteData(format: ui.ImageByteFormat.png);
return CaptureResult(data?.buffer?.asUint8List(), captureImage.width, captureImage.height);

I got this error:

E/flutter (25668): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/rendering/proxy_box.dart': Failed assertion: line 2958 pos 12: '!debugNeedsPaint': is not true.
E/flutter (25668): #0      ScreenshotController.captureAsUiImage.<anonymous closure>
package:screenshot/screenshot.dart:78
E/flutter (25668): #1      new Future.delayed.<anonymous closure> (dart:async/future.dart:326:39)
E/flutter (25668): #2      _rootRun (dart:async/zone.dart:1182:47)
E/flutter (25668): #3      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (25668): #4      _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (25668): #5      _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (25668): #6      _rootRun (dart:async/zone.dart:1190:13)
E/flutter (25668): #7      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (25668): #8      _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (25668): #9      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (25668): #10     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (25668): #11     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (25668): #12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (25668):

Please help. Thank you.

@mrtungdev
Copy link
Author

This error shows when I set offstage (Off screen), sometimes it works, sometimes not.

@ritheshSalyan
Copy link
Collaborator

@ImTung If you are rendering widget offscreen the you can make use of captureFromWidget function.

@yichaosun
Copy link

yichaosun commented Aug 20, 2024

see here bro, the render tree haven't completed, not about offscreen. in old device or simulation, will happen frequency. let't do ensure the render complete

1、warp with WidgetsBinding.instance.addPostFrameCallback

    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await screenshotController.capture(delay: const Duration(milliseconds: 100)).then((Uint8List? image) async {
        if (image != null) {
          final directory = await getApplicationDocumentsDirectory();
          final imagePath = await File('${directory.path}/image.png').create();
          await imagePath.writeAsBytes(image);

          logger.i("create img");
                final result =
                await ImageGallerySaver.saveImage(image);
        }
      });
    });

2、

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants