The MaterialApp widget is Root widget of every flutter app. MaterialApp support various type of theme suggestions to customize its children. One of them is theme. Theme property supports ThemeData() which can set default text font family for all the Text children present inside Material app widget.
Flutter Set Default Text Font Family For Whole App:
1. In our first code example, We are calling font family which is by default comes with flutter. We are calling Cursive font family in ThemeData.
theme: ThemeData(
fontFamily: 'Cursive',
),
2. Code for MaterialApp widget.
MaterialApp(
theme: ThemeData(
fontFamily: 'Cursive',
),
home: const Scaffold(
body: SafeArea(
child: Center(
child: Column(children: [
Text(
'Default Font Family For Complete App',
style: TextStyle(fontSize: 24),
textAlign: TextAlign.center,
),
Text(
'Text Two',
style: TextStyle(fontSize: 24),
),
Text(
'Text Three',
style: TextStyle(fontSize: 24),
),
Text(
'Text Four',
style: TextStyle(fontSize: 24),
)
])))))
Source code for main.dart file:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() => runApp(const App());
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'Cursive',
),
home: const Scaffold(
body: SafeArea(
child: Center(
child: Column(children: [
Text(
'Default Font Family For Complete App',
style: TextStyle(fontSize: 24),
textAlign: TextAlign.center,
),
Text(
'Text Two',
style: TextStyle(fontSize: 24),
),
Text(
'Text Three',
style: TextStyle(fontSize: 24),
),
Text(
'Text Four',
style: TextStyle(fontSize: 24),
)
])))));
}
}
Screenshot of App:
You can also use Custom fonts as default font family for the flutter app. First you need to integrate custom fonts in your app. I have already made a tutorial regarding this topic. You can visit the article from HERE.
Comments
Post a Comment