Flutter Tutorials

Flutter app development tutorials


flutter – How to use Google Fonts

main.dart


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

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(primarySwatch: Colors.pink),
      home: Scaffold(
          appBar: AppBar(
              title: const Text("Flutter - Google Fonts")
          ),
          body: bodyContent()
      ),
    ),
  );
}

bodyContent(){
  // dependencies: google_fonts: ^2.2.0
  return Column(
      children: [
        box(
            "Cute Font",
            GoogleFonts.cuteFont(textStyle: const TextStyle(fontSize: 50))
        ),
        box(
            "Rubik Beastly",
            GoogleFonts.rubikBeastly(
                textStyle: const TextStyle(fontSize: 50)
            )
        ),
        box(
            "Pacifico",
            GoogleFonts.pacifico(textStyle: const TextStyle(fontSize: 50))
        )
      ]
  );
}

box(String fontName, TextStyle style){
  return Container(
      height: 150, width: double.infinity,
      color: Colors.pink.shade50,
      margin: const EdgeInsets.all(8),
      child: Text(
        fontName,
        style: style,
        textAlign: TextAlign.center,
      ),
      alignment: Alignment.center
  );
}

More flutter tutorials



About Me

Flutter Developer

Design a site like this with WordPress.com
Get started