Skip to content

SVG radialGradient with negative cx and gradientTransform matrix fails to render correctly after Flutter upgrade #171854

@guoxz

Description

@guoxz

Steps to reproduce

  1. Create a Flutter project with the flutter_svg package.
  2. Add an SVG asset that includes a with:
    a negative cx value.
    a gradientTransform="matrix(...)".

Run on Flutter 3.29.1 or later.

Expected results

The rectangle is filled with a radial gradient, rendered correctly regardless of the negative cx.

Actual results

The gradient is not rendered incorrectly but it was ok with flutter 3.27.0

Code sample

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(body: Center(child: GradientExample())),
    );
  }
}

class GradientExample extends StatefulWidget {
  const GradientExample({super.key});

  @override
  State<GradientExample> createState() => _GradientExampleState();
}

class _GradientExampleState extends State<GradientExample> {
  @override
  Widget build(BuildContext context) {
    final svgString = '''
 <svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
     <defs>
       <radialGradient id="myGradient"
         cx="-50"
         cy="100"
         r="80"
         gradientTransform="matrix(0,1,2.0,0,40,300)">
         <stop offset="0%" stop-color="red" />
         <stop offset="100%" stop-color="blue" />
       </radialGradient>
     </defs>
     <rect x="0" y="0" width="400" height="400" fill="url(#myGradient)" />
   </svg>
''';

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SvgPicture.string(
          svgString,
          height: 240,
          width: 240,
          allowDrawingOutsideViewBox: true,
        ),
        const SizedBox(height: 20),
      ],
    );
  }
}



### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]

Flutter Doctor output

[✓] Flutter (Channel stable, 3.29.1, on macOS 15.4.1 24E263 darwin-arm64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.100.2)
[✓] Connected device (4 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.team-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions