0

After upgrade flutter with null safe i'm facing this error

            'assets/images/bg111.svg',
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
          ),```

Error:
════════ Exception caught by SVG ═══════════════════════════════════════════════
The following assertion was thrown while parsing AssetBundlePictureKey(bundle: PlatformAssetBundle#0293d(), name: "assets/images/bg111.svg", colorFilter: null) in _getDefinitionPaint:
Failed to find definition for url(#pattern0)

5 Answers5

6

This occurs because you are using the element before defining it. For me the solution was moving the entire defs tag and its content to immediately after the opening svg tag

IzyPro
  • 73
  • 5
1

When using the Flutter SvgPicture package, I fall into the same problem.

I solve this issue by exporting the file from Figam as PDF and then converting the pdf file to SVG.

Here are the steps I follow:

  1. Save as (.pdf) from Figma/Adobe XD.
  2. Then go to Zamzar and convert the PDF file as SVG Image.
  3. Use this image & Boom !!!

The problem is solved !!!

Md. Al-Amin
  • 690
  • 3
  • 13
0

Try below code hope its help to you. used flutter_svg: ^1.0.0 current version of svg dependency here.

Your widget:

 SvgPicture.asset(
   'assets/images/water.svg',
    // height: MediaQuery.of(context).size.height,
    // width: MediaQuery.of(context).size.width,
 ),

Your pubspec.yaml file

assets:
   - assets/images/

Result screen->image

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
0

As user @Mark Hardy said:

This arises in Android builds from a combination of:

Using compileSdkVersion 31,
With JDK8,
Having any Lambda style related code somewhere (else error may not happen).
The default android toolchains have moved to JDK11 now, you must use JDK11 when you change any of the Android API target versions from 30 to 31.

Semi duplicate of unrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)

Bruno J.
  • 248
  • 2
  • 13
-2

Bit late, but I had the same problem and fixed it by opening the svg and moving the ... to the top.

Zia Ullah
  • 27
  • 5