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

add custom size when capture invisible widget #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lib/screenshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ library screenshot;

// import 'dart:io';
import 'dart:async';
import 'dart:developer';
import 'dart:typed_data';
import 'src/platform_specific/file_manager/file_manager.dart';
// import 'package:path_provider/path_provider.dart';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
// import 'package:path_provider/path_provider.dart';
import 'dart:ui' as ui;

import 'src/platform_specific/file_manager/file_manager.dart';

///
///
Expand Down Expand Up @@ -93,12 +94,11 @@ class ScreenshotController {
///
///
///
Future<Uint8List> captureFromWidget(
Widget widget, {
Duration delay: const Duration(seconds: 1),
double? pixelRatio,
BuildContext? context,
}) async {
Future<Uint8List> captureFromWidget(Widget widget,
{Duration delay: const Duration(seconds: 1),
double? pixelRatio,
BuildContext? context,
Size? customSize}) async {
///
///Retry counter
///
Expand All @@ -119,9 +119,9 @@ class ScreenshotController {
}

final RenderRepaintBoundary repaintBoundary = RenderRepaintBoundary();

Size logicalSize = ui.window.physicalSize / ui.window.devicePixelRatio;
Size imageSize = ui.window.physicalSize;
final Size rootSize = customSize ?? ui.window.physicalSize;
Size logicalSize = rootSize / ui.window.devicePixelRatio;
Copy link

@aaronreulkhoo aaronreulkhoo Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the use case of generating a consistent image of some document across phones, the logical size should be set to the customSize - have confirmed this through testing, otherwise only the generated bitmap size is consistent.

Size imageSize = rootSize;

assert(logicalSize.aspectRatio.toPrecision(5) ==
imageSize.aspectRatio.toPrecision(5));
Expand Down Expand Up @@ -163,7 +163,9 @@ class ScreenshotController {
///
///

buildOwner.buildScope(rootElement,);
buildOwner.buildScope(
rootElement,
);
buildOwner.finalizeTree();

pipelineOwner.flushLayout();
Expand Down