Skip to content

[flutter_svg] Flutter - how add custom font for svg image? #158691

Closed

Description

@stuartmorgan-g

Imported from dnfield/flutter_svg#680

Original report by @FetFrumos on Mar 11, 2022

I have svg image(export from Adobe Xd). For the correct display of this file, I need to install an additional font in the system(MAC or Windows) - then the picture is displayed correctly, without this font it is incorrect. but I need to display this drawing in application. I using flutter_svg plugin. I download ttf of font, add in assets and pubspec. But after that it doesn't work either. how add custom font for svg image(with flutter_svg)?


Comment by @dnfield on Mar 13, 2022
I'd find it helpful if you shared a small but complete example of the issue.

Some places where this could possibly go wrong:

Obviously if it's that last point, there's a bug in this package. A reproduction case would be able to narrow this down.


Comment by @L4hibYoussef on Mar 15, 2023
Is there any updates on this. I am appearing to have the same issue. Font is loaded before image is rendered and font is available for use in the app. I am building the app for web using canvaskit.


Comment by @devalev on Jul 12, 2023

Is there any updates on this. I am appearing to have the same issue. Font is loaded before image is rendered and font is available for use in the app. I am building the app for web using canvaskit.

You need to load the font when executing the application.

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

void loadFont() async {
  var fontLoader = FontLoader("FontName");
  fontLoader.addFont(rootBundle.load('fonts/FontName.ttf'));
  await fontLoader.load();
}

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

  @override
  Widget build(BuildContext context) {
    loadFont();
    return Container();
  }
}

Please note that sometimes the font-family is specified in extra quotes in the svg file

font-family="FontName"

and

font-family="'FontName'"

these are different things, and, accordingly, you need to import different fonts

var fontLoader = FontLoader("FontName");

var fontLoader = FontLoader("'FontName'");

Activity

  1. added
    p: flutter_svgThe Flutter SVG drawing packages
    packageflutter/packages repository. See also p: labels.
    on Nov 13, 2024
  2. darshankawar commented on Nov 28, 2025

    @darshankawar
    Member

    You need to load the font when executing the application.

    I'll close this based on the solution given above. If anybody still sees this as an issue with latest plugin and stable version, please file new issue with relevant details using issue template.

    /cc @FetFrumos and @L4hibYoussef

  3. github-actions commented on Dec 12, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.r: solvedIssue is closed as solved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions