FontScaler is a lightweight Flutter package that allows you to dynamically adjust the text scale across your entire app. It supports predefined scale levels (like small, medium, large) and a custom mode for user-defined scaling. Optional persistent storage using SharedPreferences lets you retain the user’s preference across sessions.
- ✅ Supports Android,IOS,Web
- ✅ Predefined scale levels: micro, small, medium, default, large, xl, etc.
- ✅ Custom font scaling (e.g., customValue: 2.25)
- ✅ Persist user settings using SharedPreferences
- ✅ MediaQuery-aware text scaling
- ✅ Easy integration with global access using FontScalerProvider.of(context)
| Output 1 | Output 2 |
|---|---|
![]() |
![]() |
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
font_scaler: ^1.0.3
Import it:
import 'package:font_scaler/font_scaler.dart';
1.Initialize in main.dart
void main() {
// Need to Wrap MyApp with FontScaler
runApp(FontScaler(
child: MyApp(),
));
}
- Pass Builder in Material App
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Need to Add FontScalerProvider.of(context).builder to reflect the changes
builder: FontScalerProvider.of(context).builder,
home: HomeScreen(),
);
}
}- Update the text scale from anywhere
// default Option
FontScalerProvider.of(context).updateFontScale(FontScale.large);
// Custom option with customValue
FontScalerProvider.of(context).updateFontScale(FontScale.custom, customValue: 2.4);
- Here is the list of enum you can use
// Default Enum
enum FontScale {
ultraMicro,
micro,
extraSmall,
small,
medium,
fDefault,
large,
extraLarge,
doubleXL,
ultraXL,
custom,
}
// Just Pass like this
// EX:
FontScalerProvider.of(context).updateFontScale(FontScale.medium);- Get the current Selected Font Scale type
// This will return the currentFontScale
FontScalerProvider.of(context).currentFontScale;
Let users control font sizes
ElevatedButton(
onPressed: () {
FontScalerProvider.of(context)
.updateFontScale(FontScale.custom, customValue: 1.25);
},
child: Text("Increase Font Size"),
);
Let users control font sizes
Slider(
min: 1,
max: 5,
value: slideValue,
onChanged: (double value) {
FontScalerProvider.of(
context,
).updateFontScale(FontScale.custom, customValue: value);
setState(() {
slideValue = value;
});
},
),
Using SharedPreferences user can save the selected font Scale locally whenever app restarts it will take the value from local storage
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
font_scaler: ^1.0.3
shared_preferences: any
Import it:
import 'package:font_scaler/font_scaler.dart';
import 'package:shared_preferences/shared_preferences.dart';
1.Initialize in main.dart
void main()async{ // Make this Async
// Add this Line
WidgetsFlutterBinding.ensureInitialized();
// Create SharedPreferences Instance
final SharedPreferences prefs = await SharedPreferences.getInstance();
// Need to Wrap MyApp with FontScaler
runApp(FontScaler(
// savePermanent will save the selected fontScale locally
// savePermanent work with SharedPreferences Instance
// So Whenever the app reopens the font Scale will be same as user selected last time
savePermanent: true,
// Need to pass SharedPreferences Instance that will use in storing the data locally
prefs: prefs,
child: MyApp()));
}
- Pass Builder in Material App
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Need to Add FontScalerProvider.of(context).builder to reflect the changes
builder: FontScalerProvider.of(context).builder,
home: HomeScreen(),
);
}
}- Update the text scale from anywhere
// default Option
FontScalerProvider.of(context).updateFontScale(FontScale.large);
// Custom option with customValue
FontScalerProvider.of(context).updateFontScale(FontScale.custom, customValue: 1.4);
- You can clear the saved font Scale and set it to default
// This Will Clear the change and remove from local storage and set back to default fontScale
FontScalerProvider.of(context).clear();
Star project on Github


