xxxxxxxxxx
flutter:
fonts:
- family: YourFontFamily
fonts:
- asset: fonts/YourFontRegular.ttf
xxxxxxxxxx
flutter:
fonts:
- family: Proxima
fonts:
- asset: lib/fonts/ProximaNova-Regular.otf
In case you are using an emulator, go to the terminal and type "flutter clean" then "flutter pub get" to update the font used.
xxxxxxxxxx
MaterialApp(
theme: ThemeData(
textTheme: GoogleFonts.montserratTextTheme(
Theme.of(context).textTheme,
),
),
)
How to add a custom font to Pubspec.yaml
xxxxxxxxxx
flutter:
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
- asset: fonts/Raleway-Italic.ttf
style: italic
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Regular.ttf
- asset: fonts/RobotoMono-Bold.ttf
weight: 700
xxxxxxxxxx
fonts:
- family: Raleway
fonts:
- asset: fonts/Raleway-Regular.ttf
- asset: fonts/Raleway-Italic.ttf
style: italic
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Regular.ttf
- asset: fonts/RobotoMono-Bold.ttf
weight: 700
xxxxxxxxxx
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Custom Fonts Demo',
theme: ThemeData(
// Define a custom font family
fontFamily: 'Raleway',
// Apply the default visual style of the theme to the Text widgets
textTheme: TextTheme(
bodyText2: TextStyle(fontSize: 20),
),
),
home: Scaffold(
appBar: AppBar(
title: Text('Custom Fonts'),
),
body: Center(
child: Text(
'Hello Flutter!',
style: TextStyle(fontFamily: 'Raleway', fontSize: 30),
),
),
),
);
}
}
xxxxxxxxxx
flutter:
fonts:
- family: MyCustomFont
fonts:
- asset: fonts/MyCustomFont.ttf