Repository navigation
-
componentMatrixGolden— new API for small widgets at their intrinsic size. Sister function tomatrixGolden/screenMatrixGoldenfor component-level testing (buttons, badges, chips, list tiles). Instead of rendering inside a fullScaffoldand capturing the whole 375×667 viewport with the widget centered in 95% whitespace, the function keeps theMaterialAppcontext (so theme/fonts/icons/locale all work) but anchors the widget viaAlign(widthFactor: 1, heightFactor: 1)and places theRepaintBoundarydirectly around it. The resulting PNG is exactly widget-sized plus optional padding.componentMatrixGolden( 'ShadButton', scenarios: [ MatrixScenario('primary', builder: () => const ShadButton(child: Text('Click'))), MatrixScenario('destructive', builder: () => const ShadButton.destructive(child: Text('Delete'))), ], axes: const MatrixAxes(themes: [MatrixTheme.light, MatrixTheme.dark]), );
Configuration:
pixelRatio: double(default2.0) — PNG resolution in physical pixels = widget logical size × this value.padding: EdgeInsets(defaultEdgeInsets.all(8)) — visual breathing room around the widget; passEdgeInsets.zerofor the tightest crop.
File naming drops the device segment:
goldens/<test>/<scenario>/<theme>_<locale>_<dir>_<scale>.png. Thedevicesfield ofMatrixAxesis ignored in component mode because intrinsic size does not depend on device geometry.Limitations: widgets without an intrinsic size (e.g. plain
Container()with nowidth/height) throw a layout error — wrap them inSizedBox(width:..., height:...). Widgets that need anOverlayancestor (Tooltip,showDialog,Heroanimations across routes) still work because we keep the fullMaterialAppcontext, butScaffold-positioned widgets (AppBar, FAB) belong inmatrixGolden.