Custom fonts

This article shows how to add and use custom font.

Download and extract files in assets/fonts folder.

Add font to pubspec.yaml file and specify a name, here PTSans.

  fonts:
    - family: PTSans
      fonts:
        - asset: assets/fonts/PT_Sans-Web-Regular.ttf
        - asset: assets/fonts/PT_Sans-Web-Italic.ttf
          style: italic

Set font in your application, theme property.
The name must match the one you specified in pubspec.yaml file.

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    var config = AppConfig.of(context);

    return MaterialApp(
      title: config.appName,
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: 'PTSans',
        primaryColor: Color(0xFF005479),
        buttonColor: Color(0xFFcd5b1c),
        toggleableActiveColor: Color(0xFFcd5b1c),
      ),
      home: widget.defaultHomePage,
      routes: <String, WidgetBuilder>{
        "/login": (BuildContext context) => widget.loginPage,
        "/home": (BuildContext context) => widget.homePage,
      },
    );
  }
}