Skip to content

Commit

Permalink
Remove default SvgTheme argument preventing DefaultSvgTheme works…
Browse files Browse the repository at this point in the history
… correctly (#485)

The default SvgTheme argument prevents `DefaultSvgTheme` provider works
correctly. This should be null and works as a passthrough behavior

## What does this change?

Remove default `SvgTheme` from svg generator

Fixes #484 🎯

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
  • Loading branch information
mym0404 authored Mar 18, 2024
1 parent b45112b commit 063458a
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $ dart packages/command/bin/flutter_gen_command.dart --config example/pubspec.ya

Or melos
```sh
$ melos gen:example:command
$ melos gen:examples:command
```

#### Use as part of build_runner
Expand Down
2 changes: 1 addition & 1 deletion examples/example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class SvgGenImage {
WidgetBuilder? placeholderBuilder,
String? semanticsLabel,
bool excludeFromSemantics = false,
SvgTheme theme = const SvgTheme(),
SvgTheme? theme,
ColorFilter? colorFilter,
Clip clipBehavior = Clip.hardEdge,
@deprecated Color? color,
Expand Down
2 changes: 2 additions & 0 deletions examples/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dev_dependencies:
lints: ^2.0.0
build_runner: ^2.0.0
flutter_gen_runner: ^5.4.0
flutter_test:
sdk: flutter

flutter_gen:
output: lib/gen/ # Optional (default: lib/gen/)
Expand Down
53 changes: 53 additions & 0 deletions examples/example/test/svg_integrations_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@TestOn('vm')
import 'package:example/gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_test/flutter_test.dart';

class SvgIntegrationsTest extends StatelessWidget {
const SvgIntegrationsTest({required this.theme});

final SvgTheme theme;

@override
Widget build(BuildContext context) {
return DefaultSvgTheme(
theme: theme,
child: MyAssets.images.icons.dartTest.svg(),
);
}
}

void main() {
group('Test SvgTheme behavior', () {
var testTheme = SvgTheme(currentColor: Colors.red);

testWidgets('Passed theme should be null', (widgetTester) async {
await widgetTester.pumpWidget(SvgIntegrationsTest(theme: testTheme));

var finder = find.byType(SvgPicture);
expect(finder, findsOneWidget);

var svgWidget = widgetTester.widget<SvgPicture>(finder);
var loader = svgWidget.bytesLoader as SvgAssetLoader;

expect(loader.theme, isNull);
});

testWidgets(
'Taken theme of SvgAssetLoader equals with one passed to parent DefaultSvgTheme',
(widgetTester) async {
await widgetTester.pumpWidget(SvgIntegrationsTest(theme: testTheme));

var finder = find.byType(SvgPicture);
expect(finder, findsOneWidget);

var svgWidget = widgetTester.widget<SvgPicture>(finder);
var loader = svgWidget.bytesLoader as SvgAssetLoader;

var svgCacheKey = loader.cacheKey(widgetTester.element(finder));

expect(svgCacheKey.theme, testTheme);
});
});
}
2 changes: 1 addition & 1 deletion examples/example_resources/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class SvgGenImage {
WidgetBuilder? placeholderBuilder,
String? semanticsLabel,
bool excludeFromSemantics = false,
SvgTheme theme = const SvgTheme(),
SvgTheme? theme,
ColorFilter? colorFilter,
Clip clipBehavior = Clip.hardEdge,
@deprecated Color? color,
Expand Down
13 changes: 11 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ scripts:
description: flutter pub run build_runner build --delete-conflicting-outputs

test:
run: melos test:dart --no-select
description: dart test
run: melos test:dart --no-select && melos test:flutter --no-select
description: dart & flutter test

test:dart:
run: dart test
Expand All @@ -81,6 +81,15 @@ scripts:
dependsOn: test
description: dart test

test:flutter:
run: flutter test
exec:
failFast: true
packageFilters:
flutter: true
dependsOn: flutter_test
description: flutter test

coverage:
run: |
bash ./scripts/coverage.sh packages/core
Expand Down
2 changes: 1 addition & 1 deletion packages/command/example/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/example/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
WidgetBuilder? placeholderBuilder,
String? semanticsLabel,
bool excludeFromSemantics = false,
SvgTheme theme = const SvgTheme(),
SvgTheme? theme,
ColorFilter? colorFilter,
Clip clipBehavior = Clip.hardEdge,
@deprecated Color? color,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test_resources/actual_data/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runner/example/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 063458a

Please sign in to comment.