Repository: FlutterGen/flutter_gen

Issue:
[BUG]: flutter_svg `DefaultSvgTheme` not working
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Version

5.4.0

### Command type

build_runner (Default)

### What happened?

The presence of default `SvgTheme` argument of svg output prevents `DefaultSvgTheme` in `flutter_svg` works correctly.

```dart
SVG.cube.svg(width: 64, theme: SvgTheme(currentColor: Colors.red)),
SvgPicture.asset('assets/svg/cube.svg',
    width: 64, theme: SvgTheme(currentColor: Colors.red)),
```

![image](https://github.com/FlutterGen/flutter_gen/assets/33388801/384681b4-377a-468b-894b-f60992058d42)

```dart
child: DefaultSvgTheme(
  theme: SvgTheme(currentColor: Colors.red),
  child: Column(
    children: [
      SVG.cube.svg(width: 64),
      SvgPicture.asset('assets/svg/cube.svg', width: 64),
```

![image](https://github.com/FlutterGen/flutter_gen/assets/33388801/2de2e38e-9f78-4f54-91a4-0850b9a9a713)

### Relevant a pubspec.yaml.

_No response_

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct



Fix patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7083d3593..af2b1a5a6 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -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
diff --git a/examples/example/lib/gen/assets.gen.dart b/examples/example/lib/gen/assets.gen.dart
index a545b3d40..24cbc91bb 100644
--- a/examples/example/lib/gen/assets.gen.dart
+++ b/examples/example/lib/gen/assets.gen.dart
@@ -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,
diff --git a/examples/example/pubspec.yaml b/examples/example/pubspec.yaml
index 4365cd909..60e1744f3 100644
--- a/examples/example/pubspec.yaml
+++ b/examples/example/pubspec.yaml
@@ -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/)
diff --git a/examples/example_resources/lib/gen/assets.gen.dart b/examples/example_resources/lib/gen/assets.gen.dart
index f13a1c230..e5962d361 100644
--- a/examples/example_resources/lib/gen/assets.gen.dart
+++ b/examples/example_resources/lib/gen/assets.gen.dart
@@ -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,
diff --git a/melos.yaml b/melos.yaml
index 15f863f31..5f1421657 100644
--- a/melos.yaml
+++ b/melos.yaml
@@ -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
@@ -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
diff --git a/packages/command/example/lib/gen/assets.gen.dart b/packages/command/example/lib/gen/assets.gen.dart
index 493b86508..b0d18b481 100644
--- a/packages/command/example/lib/gen/assets.gen.dart
+++ b/packages/command/example/lib/gen/assets.gen.dart
@@ -286,7 +286,7 @@ class SvgGenImage {
     WidgetBuilder? placeholderBuilder,
     String? semanticsLabel,
     bool excludeFromSemantics = false,
-    SvgTheme theme = const SvgTheme(),
+    SvgTheme? theme,
     ColorFilter? colorFilter,
     @deprecated Color? color,
     @deprecated BlendMode colorBlendMode = BlendMode.srcIn,
diff --git a/packages/core/example/lib/gen/assets.gen.dart b/packages/core/example/lib/gen/assets.gen.dart
index 29aa6b866..75a6cc699 100644
--- a/packages/core/example/lib/gen/assets.gen.dart
+++ b/packages/core/example/lib/gen/assets.gen.dart
@@ -284,7 +284,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,
diff --git a/packages/core/lib/generators/integrations/svg_integration.dart b/packages/core/lib/generators/integrations/svg_integration.dart
index 2c56af45f..74f1be6f3 100644
--- a/packages/core/lib/generators/integrations/svg_integration.dart
+++ b/packages/core/lib/generators/integrations/svg_integration.dart
@@ -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,
diff --git a/packages/runner/example/lib/gen/assets.gen.dart b/packages/runner/example/lib/gen/assets.gen.dart
index 19d4603ed..7d2d00a14 100644
--- a/packages/runner/example/lib/gen/assets.gen.dart
+++ b/packages/runner/example/lib/gen/assets.gen.dart
@@ -277,7 +277,7 @@ class SvgGenImage {
     WidgetBuilder? placeholderBuilder,
     String? semanticsLabel,
     bool excludeFromSemantics = false,
-    SvgTheme theme = const SvgTheme(),
+    SvgTheme? theme,
     ColorFilter? colorFilter,
     @deprecated Color? color,
     @deprecated BlendMode colorBlendMode = BlendMode.srcIn,


Test patch:
diff --git a/examples/example/test/svg_integrations_test.dart b/examples/example/test/svg_integrations_test.dart
new file mode 100644
index 000000000..5db3078d1
--- /dev/null
+++ b/examples/example/test/svg_integrations_test.dart
@@ -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);
+    });
+  });
+}
diff --git a/packages/core/test_resources/actual_data/assets.gen.dart b/packages/core/test_resources/actual_data/assets.gen.dart
index d423ae32a..6e149848f 100644
--- a/packages/core/test_resources/actual_data/assets.gen.dart
+++ b/packages/core/test_resources/actual_data/assets.gen.dart
@@ -249,7 +249,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,
diff --git a/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart b/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart
index 37926262a..6cbb1084f 100644
--- a/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart
+++ b/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart
@@ -167,7 +167,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,
diff --git a/packages/core/test_resources/actual_data/assets_parse_metadata.gen.dart b/packages/core/test_resources/actual_data/assets_parse_metadata.gen.dart
index d6fa4c641..4a1269d6a 100644
--- a/packages/core/test_resources/actual_data/assets_parse_metadata.gen.dart
+++ b/packages/core/test_resources/actual_data/assets_parse_metadata.gen.dart
@@ -258,7 +258,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,
diff --git a/packages/core/test_resources/actual_data/assets_svg_integrations.gen.dart b/packages/core/test_resources/actual_data/assets_svg_integrations.gen.dart
index 64c68780f..4038ac0b2 100644
--- a/packages/core/test_resources/actual_data/assets_svg_integrations.gen.dart
+++ b/packages/core/test_resources/actual_data/assets_svg_integrations.gen.dart
@@ -58,7 +58,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,