xxxxxxxxxx
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.montserratTextTheme(
Theme.of(context).textTheme,
),
),
)
xxxxxxxxxx
flutter:
fonts:
- family: YourFontFamily
fonts:
- asset: fonts/YourFontRegular.ttf
xxxxxxxxxx
flutter:
fonts:
- family: MyCustomFont
fonts:
- asset: fonts/MyCustomFont.ttf
xxxxxxxxxx
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Text Fonts in Flutter'),
),
body: Center(
child: Text(
'Hello World',
style: TextStyle(
fontSize: 20,
fontFamily: 'Roboto', // Replace 'Roboto' with the desired font
fontWeight: FontWeight.bold, // Set font weight if desired
),
),
),
),
);
}
}
Add google_fonts to your pubspec.yaml file and add it to your Text widget like this:
xxxxxxxxxx
Text('Example Text', style: GoogleFonts.inter(
textStyle: TextStyle(
fontSize: 40, color: primaryColor,
fontWeight: FontWeight.w700,))