didChangeTextScaleFactor method
Called when the platform's text scale factor changes.
This typically happens as the result of the user changing system preferences, and it should affect all of the text sizes in the application.
This method exposes notifications from Window.onTextScaleFactorChanged.
class TextScaleFactorReactor extends StatefulWidget {
const TextScaleFactorReactor({ Key key }) : super(key: key);
@override
_TextScaleFactorReactorState createState() => _TextScaleFactorReactorState();
}
class _TextScaleFactorReactorState extends State<TextScaleFactorReactor> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
double _lastTextScaleFactor;
@override
void didChangeTextScaleFactor() {
setState(() { _lastTextScaleFactor = ui.window.textScaleFactor; });
}
@override
Widget build(BuildContext context) {
return Text('Current scale factor: $_lastTextScaleFactor');
}
}
See also:
- MediaQuery.of, which provides a similar service with less boilerplate.
Implementation
void didChangeTextScaleFactor() { }