child: RichText(
textAlign: TextAlign.start,
text: const TextSpan(
text: "What are you looking for?", //here
style: TextStyle(
color: Colors.black87,
fontSize: 18.0,
fontWeight: FontWeight.bold)),
),
help me to insert google font on the text section. This is the code style: GoogleFonts.hammersmithOne()
3
Answers
You can use the font in the
style
property of theText
widget.Example:
You can add
Google Fonts
two ways , whenonline
andoffline
Online
Download package
google_fonts
, it fetchesgoogle fonts
from the internet.add import statement
import 'package:google_fonts/google_fonts.dart'
Use it in the style
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 thegoogle_fonts
folder.Open the
pubspec.yaml
file, Under the assets: section add the-google_fonts/
Note: Changing Google Font at App Level
If you want the font to change throughtout the app use the following code:
Add dependency in your pubspec.yaml google_fonts: ^3.0.1
then use style property in your text widget