Skip to main content

Flutter Set Google Fonts as Default Font Family for Whole App

In our previous article we have learned about integrating Google fonts in flutter app. In this tutorial we are going more further by setting up Google fonts family as our default font family for complete app. Means after defining default Google font for app anywhere in the app when we created a Text widget then automatically defined Google font will be applied on that text.
Flutter Set Google Fonts as Default Font Family for Whole App

Flutter Set Google Fonts as Default Font Family for Whole App:

1. First you need to learn about how you can integrate Google fonts in flutter app. I have made a tutorial on this topic also, You can read it from HERE.
2. Import google_fonts.dart pacakge in your project's main.dart file.
3. Call Google font in the theme section of material app widget.
  theme: ThemeData(
          fontFamily: GoogleFonts.poppins().fontFamily,
        ),
4. You can call any desired Google font using this method.
Source code for main.dart file:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

void main() => runApp(const App());

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          fontFamily: GoogleFonts.poppins().fontFamily,
        ),
        home: const Scaffold(
            body: SafeArea(
                child: Center(
                    child: Column(children: [
          Text(
            'Flutter Set Google Fonts as Default Text Font Family For Whole App',
            style: TextStyle(
                fontSize: 24,
                color: Colors.deepOrange,
                fontWeight: FontWeight.bold),
            textAlign: TextAlign.center,
          ),
          Text(
            'Text Two',
            style: TextStyle(fontSize: 24),
          ),
          Text(
            'Text Three',
            style: TextStyle(fontSize: 24),
          ),
          Text(
            'Text Four',
            style: TextStyle(fontSize: 24),
          )
        ])))));
  }
}

Comments