Skip to content

Commit e61994c

Browse files
authored
[flutter_svg] Add golden widget tests for SVG alpha masks (flutter#13245)
Adds golden widget tests in `flutter_svg` for SVG alpha masks (`mask-type="alpha"` and `style="mask-type:alpha"`) and bumps the `vector_graphics_compiler` dependency constraint to `^1.3.1`. Follow-up to flutter/packages#13025 Part of flutter#158734 ### Added Golden Tests * `alpha_mask.opaque_style.png`: Opaque `#000000` mask using inline CSS `style="mask-type:alpha"`. * `alpha_mask.fill_opacity.png`: Semi-transparent mask using `mask-type="alpha"` and `fill-opacity="0.5"`. * `alpha_mask.group_opacity.png`: Group opacity inside an alpha mask (`<mask mask-type="alpha"><g opacity="0.5">...</g></mask>`). * `alpha_mask.gradient.png`: Linear gradient alpha mask fading `stop-opacity` from `1` to `0`. ## Pre-Review Checklist
1 parent da40eaf commit e61994c

3 files changed

Lines changed: 102 additions & 3 deletions

File tree

‎third_party/packages/flutter_svg/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.3.1
22

3+
* Adds support for SVG alpha masks (`mask-type="alpha"`).
34
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.
45

56
## 2.3.0

‎third_party/packages/flutter_svg/pubspec.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flutter_svg
22
description: An SVG rendering and widget library for Flutter, which allows painting and displaying Scalable Vector Graphics 1.1 files.
33
repository: https://github.com/flutter/packages/tree/main/third_party/packages/flutter_svg
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_svg%22
5-
version: 2.3.0
5+
version: 2.3.1
66

77
environment:
88
sdk: ^3.11.0
@@ -14,7 +14,7 @@ dependencies:
1414
http: ^1.0.0
1515
vector_graphics: ^1.2.0
1616
vector_graphics_codec: ^1.1.11+1
17-
vector_graphics_compiler: ^1.1.14
17+
vector_graphics_compiler: ^1.3.1
1818

1919
dev_dependencies:
2020
flutter_test:

‎third_party/packages/flutter_svg/test/widget_svg_test.dart‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,104 @@ void main() {
786786
});
787787
});
788788

789+
group('SvgPicture alpha masks', () {
790+
testWidgets('opaque mask with style="mask-type:alpha"', (WidgetTester tester) async {
791+
final GlobalKey key = GlobalKey();
792+
793+
const svgStr = '''
794+
<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
795+
<mask id="m" style="mask-type:alpha">
796+
<circle cx="50" cy="50" r="40" fill="#000000" />
797+
</mask>
798+
<g mask="url(#m)">
799+
<rect width="100" height="100" fill="#FF8800" />
800+
</g>
801+
</svg>
802+
''';
803+
804+
await tester.pumpWidget(
805+
RepaintBoundary(key: key, child: SvgPicture.string(svgStr, width: 100.0, height: 100.0)),
806+
);
807+
808+
await tester.pumpAndSettle();
809+
await _checkWidgetAndGolden(key, 'alpha_mask.opaque_style.png');
810+
});
811+
812+
testWidgets('semi-transparent mask with fill-opacity', (WidgetTester tester) async {
813+
final GlobalKey key = GlobalKey();
814+
815+
const svgStr = '''
816+
<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
817+
<mask id="m" mask-type="alpha">
818+
<circle cx="50" cy="50" r="40" fill="#000000" fill-opacity="0.5" />
819+
</mask>
820+
<g mask="url(#m)">
821+
<rect width="100" height="100" fill="#FF8800" />
822+
</g>
823+
</svg>
824+
''';
825+
826+
await tester.pumpWidget(
827+
RepaintBoundary(key: key, child: SvgPicture.string(svgStr, width: 100.0, height: 100.0)),
828+
);
829+
830+
await tester.pumpAndSettle();
831+
await _checkWidgetAndGolden(key, 'alpha_mask.fill_opacity.png');
832+
});
833+
834+
testWidgets('group opacity inside alpha mask', (WidgetTester tester) async {
835+
final GlobalKey key = GlobalKey();
836+
837+
const svgStr = '''
838+
<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
839+
<mask id="m" mask-type="alpha">
840+
<g opacity="0.5">
841+
<circle cx="50" cy="50" r="40" fill="#000000" />
842+
</g>
843+
</mask>
844+
<g mask="url(#m)">
845+
<rect width="100" height="100" fill="#FF8800" />
846+
</g>
847+
</svg>
848+
''';
849+
850+
await tester.pumpWidget(
851+
RepaintBoundary(key: key, child: SvgPicture.string(svgStr, width: 100.0, height: 100.0)),
852+
);
853+
854+
await tester.pumpAndSettle();
855+
await _checkWidgetAndGolden(key, 'alpha_mask.group_opacity.png');
856+
});
857+
858+
testWidgets('gradient alpha mask', (WidgetTester tester) async {
859+
final GlobalKey key = GlobalKey();
860+
861+
const svgStr = '''
862+
<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
863+
<defs>
864+
<linearGradient id="fade" x1="0%" y1="0%" x2="100%" y2="0%">
865+
<stop offset="0%" stop-color="#000000" stop-opacity="1" />
866+
<stop offset="100%" stop-color="#000000" stop-opacity="0" />
867+
</linearGradient>
868+
</defs>
869+
<mask id="m" mask-type="alpha">
870+
<circle cx="50" cy="50" r="40" fill="url(#fade)" />
871+
</mask>
872+
<g mask="url(#m)">
873+
<rect width="100" height="100" fill="#FF8800" />
874+
</g>
875+
</svg>
876+
''';
877+
878+
await tester.pumpWidget(
879+
RepaintBoundary(key: key, child: SvgPicture.string(svgStr, width: 100.0, height: 100.0)),
880+
);
881+
882+
await tester.pumpAndSettle();
883+
await _checkWidgetAndGolden(key, 'alpha_mask.gradient.png');
884+
});
885+
});
886+
789887
testWidgets('SvgPicture - two of the same', (WidgetTester tester) async {
790888
// Regression test to make sure the same SVG can render twice in the same
791889
// view. If layers are incorrectly reused, this will fail.

0 commit comments

Comments
 (0)