flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

[QUESTION] How do I set font family with Google Fonts?

Open rivetingpeppermint opened this issue 9 months ago • 2 comments

I want to set font family for my HTML widget using Google Fonts. Here's what I've tried:

TagWrapExtension(
  tagsToWrap: {'body'},
  builder: (child) {
    return DefaultTextStyle(
      style:
          GoogleFonts.robotoFlex(letterSpacing: 0),
      child: child,
    );
  }),

That approach caused my HTML to display without any wrapping (the whole horizontal width of the content is displayed), like so: Image

While the desired result is something like this: Image

Is there another approach I can use to use Google Fonts with the HTML widget? Any ideas would be very appreciated.

rivetingpeppermint avatar Apr 07 '25 11:04 rivetingpeppermint

Any updates? or any work around to support custom fonts?

anas-lucida avatar Sep 03 '25 11:09 anas-lucida

final fredokaFamily = GoogleFonts.fredoka().fontFamily; Then

Html(
              data: content,
              style: {
                "body": Style(
                  fontFamily: fredokaFamily,
                  margin: Margins.zero,
                  padding: HtmlPaddings.zero,
                  color: appColorText,
                  fontSize: FontSize(fs14()),
                  lineHeight: const LineHeight(1.6),
                ),
...)

mminhlequang avatar Oct 20 '25 13:10 mminhlequang