Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG Compare Asset Testing #852

Closed
felipecastrosales opened this issue Feb 10, 2023 · 4 comments
Closed

SVG Compare Asset Testing #852

felipecastrosales opened this issue Feb 10, 2023 · 4 comments

Comments

@felipecastrosales
Copy link

felipecastrosales commented Feb 10, 2023

Hi!

Before the version 2.0.0, I had this test that worked fine and made the assertion I wanted.

final findAsset = find.byWidgetPredicate(
  (widget) =>
      widget is SvgPicture &&
      (widget.pictureProvider as ExactAssetPicture)
              .assetName
              .compareTo('assets/flutter.svg') ==
          0,
);

expect(findAsset, findsOneWidget);

However, after 2.0.0 this testis invalid because there were internal change in the package, e.g:

  • pictureProvider:
    The getter 'pictureProvider' isn't defined for the type 'SvgPicture'. Try importing the library that defines 'pictureProvider', correcting the name to the name of an existing getter, or defining a getter or field named 'pictureProvider'.
  • ExactAssetPicture:
    The name 'ExactAssetPicture' isn't a type, so it can't be used in an 'as' expression. Try changing the name to the name of an existing type, or creating a type with the name 'ExactAssetPicture'.

I would be like to know which is the best option to follow, with the new version of the package.

I also made a Minimal Reproducible Example:

@felipecastrosales
Copy link
Author

I found a solution for this.

Just do it this way:

final findAsset = find.byWidgetPredicate(
  (widget) =>
      widget is SvgPicture &&
      (widget.bytesLoader as SvgAssetLoader) // Here! 
              .assetName
              .compareTo('assets/flutter.svg') ==
          0,
);

Is this an interesting approach? I believe so. I'll leave the issue open as I'm open to feedback and if there's something better to be done here. And I also made the commit.

@dnfield
Copy link
Owner

dnfield commented Feb 10, 2023

Yes, this is the correct way to fix this issue.

@felipecastrosales
Copy link
Author

Ok, @dnfield. Thanks for answer. :)

@dkbast
Copy link

dkbast commented Feb 13, 2023

This would be great as part of a migration guide - btw there are still references to the picture provider in the code documentation.

@felipecastrosales felipecastrosales changed the title Flutter SVG | Compare Asset Testing SVG Compare Asset Testing Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants