Search code examples
flutterdartgoogle-font-api

how to add google fonts


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()


Solution

  • Add dependency in your pubspec.yaml google_fonts: ^3.0.1

    then use style property in your text widget

    Text('What are you looking for?',
    style: GoogleFonts.hammersmithOne(
      fontSize: 48,
      fontWeight: FontWeight.w700,
      fontStyle: FontStyle.italic,
      color: Colors.greenAccent),
    );