Saturday, April 24, 2021

Adding fonts to the project

-Import font files,ttf files.(fonts.google.com) 
-Declare font in the pubspec.yaml 
-use the font in widgets.

 pubspec.yaml

   fonts:
     - family: Schyler
       fonts:
         - asset: fonts/Schyler-Regular.ttf
         - asset: fonts/Schyler-Italic.ttf
           style: italic
     - family: Trajan Pro
       fonts:
         - asset: fonts/TrajanPro.ttf
         - asset: fonts/TrajanPro_Bold.ttf
           weight: 700


home.dart
import 'dart:ui';

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        alignment: Alignment.center,
        color: Colors.deepOrangeAccent,
        child: Text(
          "Pizza",
          textDirection: TextDirection.ltr,
          style: TextStyle(
            fontSize: 80.0,
            decoration:TextDecoration.none,
            fontFamily: 'Schyler',
          ),
        ));
  }
}

No comments:

Post a Comment