1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

flutter_genflutter_svgflutter_svg_test を利用したアプリの Widget Test で svg が表示されているかのテストコードを実装したところ、表示されているはずの svg が見つからないという事象が発生したので、調査した。

結論

SVGPicture のインスタンス生成方法によって変わることがわかった。

// SvgPicture.asset('/assets/my.svg') のようにインスタンス生成していた場合は、Find by BytesLoader で紹介された記述が使える

final SvgPicture asset = SvgPicture.asset('/assets/my.svg');
expect(find.svg(asset.bytesLoader), findsOneWidget);

// flutter_gen を利用してインスタンス生成した場合(ソースコード上で Assets.my.svg() を利用している)は、Find by BytesLoader で紹介された記述が使えないので
// Find by svg path で紹介された記述を使う
 
final SvgPicture asset = SvgPicture.asset('/assets/my.svg');
expect(find.svg(asset.bytesLoader), findsOneWidget);


final svg = '/assets/my.svg';
expect(find.svgAssetWithPath(svg), findsOneWidget);

おわりに

ドキュメントをちゃんと読みましょう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?