import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Custom Fonts Demo',
theme: ThemeData(
fontFamily: 'Lobster',
),
home: const CustomFontScreen(),
);
}
}
class CustomFontScreen extends StatelessWidget {
const CustomFontScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Custom Fonts Demo'),
),
body: const Center(
child: Text(
'Hello in Custom Font',
style: TextStyle(fontSize: 28),
),
),
);
}
}
/*
Additional steps outside this code:
1. Add font files (e.g., Lobster-Regular.ttf) into assets/fonts/
2. Update pubspec.yaml:
flutter:
fonts:
- family: Lobster
fonts:
- asset: assets/fonts/Lobster-Regular.ttf
This setup makes the font family 'Lobster' available to use in the app.
*/We added a custom font named 'Lobster' to the Flutter app by placing the font file in the assets folder and configuring pubspec.yaml. Then, we set the app's theme fontFamily to 'Lobster' so all text uses it by default. The main text on the screen uses this font and is centered with a larger font size for visibility.
This approach shows how to load and use custom fonts in Flutter, making your app's text look unique and styled.