我需要UI对系统字体大小的更改做出React。如何订阅这些更改?
vxf3dgd41#
您可以使用WidgetsBindingObserver执行此操作
WidgetsBindingObserver
import 'package:flutter/cupertino.dart'; class MyWidget extends StatefulWidget { @override _MyWidgetState createState() => _MyWidgetState(); } class _MyWidgetState extends State<MyWidget> with WidgetsBindingObserver { @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override void didChangeMetrics() { final currentFontSize = WidgetsBinding.instance.window.textScaleFactor; print('Font size changed to $currentFontSize'); } @override Widget build(BuildContext context) { return Container(); } }
1条答案
按热度按时间vxf3dgd41#
您可以使用
WidgetsBindingObserver
执行此操作