You can add Google Fonts
two ways , when online
and offline
Online
Download package google_fonts
, it fetches google fonts
from the internet.
add import statement import 'package:google_fonts/google_fonts.dart'
Use it in the style
Text(
'This is hammersmithOne from Google Font'
style: GoogleFonts.hammersmithOne(),
),
Offline
Visit the https://fonts.google.com/ and download the hammersmithOne
font.
At the root directory, create a directory called google_fonts
.
Copy-Paste hammersmithOne.ttf
file into the google_fonts
folder.
Open the pubspec.yaml
file, Under the assets: section add the -google_fonts/
Text(
'This is hammersmithOne from Google Font',
style: GoogleFonts.getFont('hammersmithOne'),
// style: TextStyle(fontFamily: 'hammersmithOne') <-- This can also be used.
),
Note: Changing Google Font at App Level
If you want the font to change throughtout the app use the following code:
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: GoogleFonts.hammersmithOne(
Theme.of(context).textTheme,
),
// fontFamily:'hammersmithOne' <-- this can also be used
),
home: GoogleFontDemo(),
);