SachinGanesh / screenshot

Flutter Screenshot Library
https://pub.dev/packages/screenshot
MIT License
327 stars 137 forks source link

Calling screenshot.capture() on Web returns null #126

Open VincentMTAC opened 1 year ago

VincentMTAC commented 1 year ago

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /home/vincent/Android/Sdk • Platform android-33, build-tools 33.0.1 • Java binary at: /snap/android-studio/125/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted.

[✓] Chrome - develop for the web • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop • clang version 10.0.0-4ubuntu1 • cmake version 3.16.3 • ninja version 1.10.0 • pkg-config version 0.29.1

[✓] Android Studio (version 2021.3) • Android Studio at /snap/android-studio/125/android-studio • Flutter plugin version 71.0.3 • Dart plugin version 213.7433 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Connected device (3 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 32) (emulator) • Linux (desktop) • linux • linux-x64 • Ubuntu 22.10 5.19.0-38-generic • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.49

[✓] HTTP Host Availability • All required HTTP hosts are available

• No issues found!



- Reproduce steps 
Calling 
`var capture = await screenshotController.capture();`
returns null. 

- Workaround 
Call screenshotController.captureAsUiImage with a Duration(milliseconds: 50) 

My guess is that calling : 
`        ui.Image? image = await captureAsUiImage(
          delay: Duration.zero,
          pixelRatio: pixelRatio,
        );
`
Here https://github.com/SachinGanesh/screenshot/blob/master/lib/screenshot.dart#L49

While it is said: 
`  Future<ui.Image?> captureAsUiImage(
      {double? pixelRatio: 1,
      Duration delay: const Duration(milliseconds: 20)}) {
    //Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
`
But I let you decide whether it is a bug or not
vborbely commented 2 months ago

I found that on Web, you have to call Uint8List? tempImage = await screenshotController.capture() with a Duration = 0 , like:

Uint8List? tempImage = await screenshotController.capture( delay: const Duration(milliseconds: 0) );

Deishelon commented 4 weeks ago

+1

Using zero delay does not work for me