Closed MrChen2016-08-27 closed 2 years ago
字体的值现在是固定取适配中的最小值的 , 所以无论屏幕是否旋转字体大小都不会变化
ScreenUtil() 返回永远不会改变的值。 该库使用 InheritedElement 来通知更改,因此上下文的小部件及其所有后代将再次调用 build 方法以从 ScreenUtil() 获取新值。 您的代码基本上在构建方法之外声明 ScreenUtil().setSp() ,因此不会发生任何更改。 English: ScreenUtil() returns a value that will never change. The library uses InheritedElement to notify changes, so the context's widget and all its descendants will call the build method again to get the new values from ScreenUtil(). Your code basically declares ScreenUtil().setSp() outside of the build method, so nothing will change.
我在一个common.dart 设置了一个全局样式类,类似如下:
然而,我在旋转屏幕时,发现打印
CommonStyle.defaultTextStyle.fontSize
该值并没有被修改,依然是打开时初始化方向的值。 但是直接在 build 函数打印或者20.sp
,会根据旋转实时变化。我直接尝试在 state 的 build外使用变量,发现依然存在这种情况: