dsGoldenMatrix function

GoldenTestGroup dsGoldenMatrix({
  1. required String name,
  2. required Widget builder(),
  3. Iterable<DsThemeMode> themes = DsThemeMode.values,
  4. Iterable<DsDensityMode> densities = const [DsDensityMode.comfortable],
  5. Iterable<double> textScales = const [1.0],
  6. Iterable<Locale> locales = const [Locale('en')],
})

Builds one alchemist GoldenTestGroup with a scenario per combination of themes, densities, textScales and locales.

Each scenario wraps builder() in the given Locale, a MediaQuery with TextScaler.linear(scale) and a DsThemeScope (reduced motion, so a golden never captures a frame of a transition; default accent) on a color.surface.canvas background. The scenario name is <theme> <density> x<scale> <locale>.

Parameters: name is the group's label in failure messages; builder creates a fresh widget per scenario. Returns the group to pass to goldenTest(builder: ...).

For CI goldens alchemist renders text as blocks with the Ahem font on its own theme; the scope then keeps Ahem for the text theme and the default text style, so the CI image does not depend on font rendering of the host.

goldenTest('sample page', fileName: 'sample_page',
    builder: () => dsGoldenMatrix(name: 'sample page', builder: SamplePage.new));

Implementation

GoldenTestGroup dsGoldenMatrix({
  required String name,
  required Widget Function() builder,
  Iterable<DsThemeMode> themes = DsThemeMode.values,
  Iterable<DsDensityMode> densities = const [DsDensityMode.comfortable],
  Iterable<double> textScales = const [1.0],
  Iterable<Locale> locales = const [Locale('en')],
}) {
  return GoldenTestGroup(
    columns: textScales.length,
    children: [
      for (final theme in themes)
        for (final density in densities)
          for (final locale in locales)
            for (final scale in textScales)
              GoldenTestScenario(
                name:
                    '${theme.name} ${density.name} x$scale ${locale.toLanguageTag()}',
                child: _DsGoldenCell(
                  dsContext: DsContext(
                    theme: theme,
                    density: density,
                    motion: DsMotionMode.reduced,
                    accent: dsDefaultAccent,
                  ),
                  locale: locale,
                  textScale: scale,
                  child: builder(),
                ),
              ),
    ],
  );
}