flutterdarttextfont-family

Font not loading in Flutter


Everything seems to be working just fine except for the font family. Text animation is working, but every time I run my Flutter apps, it runs on the normal default font. What should I do now?

children: [
        AnimatedTextKit(
          animatedTexts: [
            TypewriterAnimatedText(
              'Hello world!',
              textStyle: const TextStyle(
                  fontSize: 32.0,
                  fontWeight: FontWeight.bold,
                  fontFamily: 'Canterbury'
              ),
              speed: const Duration(milliseconds: 200),
            ),
          ],

          totalRepeatCount: 4,
          pause: const Duration(milliseconds: 1000),
          displayFullTextOnTap: true,
          stopPauseOnTap: true,
        )
      ],
    )
  ),
);

} }


Solution

  • Make sure to add the fonts to your pubspec.yaml file. Here is an example of how to properly implement them assuming the file storing your fonts is in the root folder of your project (not the lib)

    assets:
    ...
      fonts:
        - family: Schyler
          fonts:
            - asset: fonts/Schyler-Regular.ttf
            - asset: fonts/Schyler-Italic.ttf
              style: italic