Google fonts

YAML

dependencies:
  google_fonts: ^3.0.1

Usage

One common example of using the google_fonts package is to set the font of a Text widget to a Google font. For example:

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text(
      'Hello, World!',
      style: GoogleFonts.lato(),
    );
  }
}

This sets the font of the Text widget to Lato, one of the fonts available from Google Fonts.

You can set the font size, color, and weight using the TextStyle class. For example, to set the font size to 24, the color to red, and the weight to bold, you can modify the Text widget in the previous example like this:

Text(
  'Hello, World!',
  style: GoogleFonts.lato(
    textStyle: TextStyle(
      fontSize: 24,
      color: Colors.red,
      fontWeight: FontWeight.bold,
    ),
  ),
);