BirjuVachhani / spider

A small dart library to generate Assets dart code from assets folder.
https://spider.birju.dev/
Apache License 2.0
190 stars 19 forks source link

Add List<String> values parameter to the genereted files #38

Closed Alexi-Zemcov closed 2 years ago

Alexi-Zemcov commented 2 years ago

Please, add static const List<String> values parameter to the genereted files. It woud be helpful for golden tests, for example:

class Images {
  Images._();

  static const List<String> values = [search, home, backArrow];

  static const String search = 'assets/search.png';
  static const String home = 'assets/home.png';
  static const String backArrow = 'assets/back_arrow.png';
}

In such cases, we can easily iterate all images like this:

for (final icon in Images.values) {
  /*do something cool*/
}

For exapmle, to generate an image with all the possible icons in the application like this:


void main() {
  testGoldens('Icons golden test', (tester) async {
    final builder = GoldenBuilder.column();

    for (final imagePath in Images.values) {
      builder.addScenario(
        iconPath,
        Image.asset(
          iconPath,
          height: 24,
          width: 24,
        ),
      );
    }

    await tester.pumpWidgetBuilder(
      builder.build(),
      surfaceSize: const Size(420, 3650),
      wrapper: materialAppWrapper(theme: AppTheme.defaultTheme),
    );

    await screenMatchesGolden(tester, 'icons');
  });
}