BirjuVachhani / spider

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

Feature/add list of asset values to genereted file #39

Closed zemcov-surf closed 2 years ago

zemcov-surf commented 2 years ago

Description of the Change

Add static const List values parameter to the genereted files.

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';
}

Why Should This Be In Core?

User can use variable values to iterate all assets like this:

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

Benefits

For exapmle, user can 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');
  });
}

Possible Drawbacks

In the generated asset file we have now a variable static const List<String> values that contains list of the all genereted assets.

Verification Process

I verified new functionality with data_class_generator_test.dart. I used debug points and also added one test case to the test class.

Applicable Issues

38

BirjuVachhani commented 2 years ago

@zemcov-surf Nice work!! Just minor changes and it is good to be merged.

codecov-commenter commented 2 years ago

Codecov Report

Merging #39 (861bca0) into main (fe78905) will increase coverage by 0.43%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   85.83%   86.27%   +0.43%     
==========================================
  Files          11       11              
  Lines         346      357      +11     
==========================================
+ Hits          297      308      +11     
  Misses         49       49              
Impacted Files Coverage Δ
lib/src/constants.dart 50.00% <ø> (ø)
lib/src/dart_class_generator.dart 94.16% <100.00%> (+0.20%) :arrow_up:
lib/src/data/class_template.dart 100.00% <100.00%> (ø)
lib/src/spider_config.dart 93.75% <100.00%> (+0.41%) :arrow_up:
lib/src/utils.dart 80.00% <100.00%> (+0.76%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b886c8d...861bca0. Read the comment docs.

BirjuVachhani commented 2 years ago

Merged. @zemcov-surf Thanks for your contribution! Will release this soon!