sheetSize method Null safety

  1. @Deprecated('The `sheetSize` is only useful for `display`, which should be migrated to `collate`. ' 'This feature was deprecated after v2.3.0-13.0.pre.')
Size sheetSize(
  1. {double maxWidth = _kDefaultTestViewportWidth}
)
@Deprecated('The `sheetSize` is only useful for `display`, which should be migrated to `collate`. ' 'This feature was deprecated after v2.3.0-13.0.pre.')

Returns the smallest size that can contain all recorded frames.

This is used to adjust the viewport during unit tests, i.e. the size of virtual screen. Having too many frames recorded than the default viewport size can contain will lead to overflow errors, while having too few frames means the golden file might be larger than necessary.

The sheetSize returns the smallest possible size by placing the recorded frames, each of which has a size specified by frameSize, in a row-major grid with a maximum width specified by maxWidth, and returns the size of that grid.

Setting the viewport size during a widget test usually involves TestWidgetsFlutterBinding.setSurfaceSize and WidgetTester.binding.

The maxWidth defaults to the width of the default viewport, 800.0.

This method can only be called if at least one frame has been recorded.

Implementation

@Deprecated(
  'The `sheetSize` is only useful for `display`, which should be migrated to `collate`. '
  'This feature was deprecated after v2.3.0-13.0.pre.',
)
Size sheetSize({double maxWidth = _kDefaultTestViewportWidth}) {
  assert(_recordedFrames.isNotEmpty);
  final int cellsPerRow = (maxWidth / frameSize.width).floor();
  final int rowNum = (_recordedFrames.length / cellsPerRow).ceil();
  final double width = math.min(cellsPerRow, _recordedFrames.length) * frameSize.width;
  return Size(width, frameSize.height * rowNum);
}