DiagramShapeThumbnail constructor
DiagramShapeThumbnail(
- ShapeDefinition definition, {
- required ShapeRegistry registry,
- DiagramTheme theme = DiagramTheme.light,
Implementation
factory DiagramShapeThumbnail(
ShapeDefinition definition, {
required ShapeRegistry registry,
DiagramTheme theme = DiagramTheme.light,
}) {
final shape = ShapeElement(
id: 'thumbnail',
type: definition.type,
frame: DiagramRect.fromLTWH(
0,
0,
definition.size.width,
definition.size.height,
),
style: definition.style,
textStory: definition.createTextStory('thumbnail'),
values: definition.createValues(definition.previewValues),
);
final scene = DiagramResolver(
registry: registry,
textLayout: FlutterDiagramTextLayoutEngine(),
).resolve(DiagramDocument(id: 'thumbnail', revision: 0, elements: [shape]));
final bounds = scene.bounds.inflate(6);
final size = Size(bounds.width, bounds.height);
final cache = DiagramScenePaintCache();
final camera = DiagramCamera.fixed(
DiagramCameraState(
center: bounds.center,
zoom: 1,
viewportSize: DiagramSize(bounds.width, bounds.height),
),
);
final recorder = ui.PictureRecorder();
try {
DiagramScenePainter(
scene: scene,
camera: camera,
selection: const EmptySelection(),
grid: const GridOptions(),
lodPolicy: const DiagramLodPolicy(),
paintCache: cache,
theme: theme,
contentOnly: true,
).paint(Canvas(recorder), size);
return DiagramShapeThumbnail._(recorder.endRecording(), size);
} catch (_) {
recorder.endRecording().dispose();
rethrow;
} finally {
cache.dispose();
}
}