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

Unable to capture width screenshot in Sony Xperia IV device #178

Open
Murmurl912 opened this issue Apr 29, 2024 · 0 comments
Open

Unable to capture width screenshot in Sony Xperia IV device #178

Murmurl912 opened this issue Apr 29, 2024 · 0 comments

Comments

@Murmurl912
Copy link

Here is crash log:

ERROR 'package:screenshot/screenshot.dart': Failed assertion: line 155 pos 12: 'logicalSize.aspectRatio.toStringAsPrecision(5) ==
ERROR imageSize.aspectRatio
ERROR .toStringAsPrecision(5)': is not true.
ERROR #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
ERROR #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
ERROR #2 ScreenshotController.widgetToUiImage (package:screenshot/screenshot.dart:155:12)
ERROR #3 ScreenshotController.captureFromWidget (package:screenshot/screenshot.dart:102:28)

I am using screenshot 2.3.0.
The code used to capture screenshot is:

      final capture = await screenshotController.captureFromWidget(
          SomWidget(),
          context: context,
          pixelRatio: 1080 / 390.0 / 2);

The assert is thrown in line 153:

    final RenderRepaintBoundary repaintBoundary = RenderRepaintBoundary();
    final platformDispatcher = WidgetsBinding.instance.platformDispatcher;
    final fallBackView = platformDispatcher.views.first;
    final view =
        context == null ? fallBackView : View.maybeOf(context) ?? fallBackView;
    Size logicalSize =
        targetSize ?? view.physicalSize / view.devicePixelRatio; // Adapted
    Size imageSize = targetSize ?? view.physicalSize; // Adapted

    assert(logicalSize.aspectRatio.toStringAsPrecision(5) ==
        imageSize.aspectRatio
            .toStringAsPrecision(5)); // Adapted (toPrecision was not available)

image
logicalSize = Size(417.5, 975.2)
imageSize = Size(1096.0, 2560.0)

view.physicalSize = Size(1096.0, 2560.0)
view.devicePixelRatio = 2.625

logicalSize.aspectRatio = 0.42812500000000003
imageSize.aspectRatio = 0.428125

imageSize.aspectRatio.toStringAsPrecision(5) = 0.42812
logicalSize.aspectRatio.toStringAsPrecision(5) =  0.42813

Why the assertion in line 153 is needed, a small rounding error could fail it:

    assert(logicalSize.aspectRatio.toStringAsPrecision(5) ==
        imageSize.aspectRatio
            .toStringAsPrecision(5)); // Adapted (toPrecision was not available)
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

1 participant