0

How do you add custom font for Web only?

I know that I can add font assets but I'd like to keep using system fonts for ios and android.

Do I embed <link> for google fonts in the <head> in index.html?

For example:

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap" rel="stylesheet">

1 Answer 1

1

If you are wanting to use a Google font, the https://pub.dev/packages/google_fonts package can defer loading a font until runtime. If you determine you're on the web, load the font and select it in your primary text theme. Otherwise, ignore all that. :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I didn't know about google_fonts package. I ended up doing this: ThemeData(textTheme: kIsWeb ? GoogleFonts.robotoTextTheme() : null)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.