Text widget supports multiple type of styling and one them is TextStyle with fontSize. Font size is used to Set Change Text Font Size in Flutter iOS Android App. fontSize supports double value. The default value of fontSize is 14 logical pixels. When application starts drawing text on screen then the font size multiplied by current textScaleFactor for easier us to read the Text on screen.
Contents in this project Set Change Text Font Size in Flutter iOS Android Example:
1. Import material.dart package in your app’s main.dart file.
1 |
import 'package:flutter/material.dart'; |
2. Call our main MyApp class using void main runApp().
1 |
void main() => runApp(MyApp()); |
3. Create class named as MyApp. This is our main widget class.
1 2 3 |
class MyApp extends StatelessWidget { } |
4. Create Widget Build area with Scaffold default widget.
1 2 3 4 5 6 7 8 9 10 |
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: ) ); } } |
5. Create the SafeArea widget in body section of Scaffold widget with Center widget.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: Center( child: ( ) ) ) ) ); } } |
6. Create the Text widget with Style -> Text Style -> fontSize and define font size as 28.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: Center( child: ( Text('Change Text Size in Flutter', style: TextStyle(fontSize: 28), ) ) ) ) ) ); } } |
7. Complete source code for main.dart file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: Center( child: ( Text('Change Text Size in Flutter', style: TextStyle(fontSize: 28), ) ) ) ) ) ); } } |
Screenshot: