OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.83k stars 485 forks source link

刚启动时 .sp 算出来是0 #529

Open NullCrazy opened 8 months ago

NullCrazy commented 8 months ago

作者你好,在使用最新版本5.9.0的时候,android release模式下 ,应用刚启动的时候设置 xx.sp,得到的字体大小一直是0,换之前的版本没有这个问题!大致代码如下:

` class MyHomePageState extends State { @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: const Size(360, 690), minTextAdapt: true, splitScreenMode: true, builder: (, child) { return MaterialApp( title: 'First Method', // You can use the library anywhere in the app even in theme theme: ThemeData( primarySwatch: Colors.blue, textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp), ), home: child, ); }, child: const HomePage(), ); } }

class HomePage extends StatefulWidget { const HomePage({super.key});

@override State createState() => _HomePageState(); }

class _HomePageState extends State { final TextStyle style = TextStyle( fontSize: 10.sp, );

@override Widget build(BuildContext context) { print(">>>>>>${style.fontSize}"); return const Center(child: Text("test")); } } `

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 30 days with no activity.

SkyOfFeather commented 7 months ago

5.9.0问题挺多,但没人回复,奇怪

lizhuoyuan commented 6 months ago

我把你这段代码放到了example中运行,没发现问题啊

M1sakii commented 6 months ago

release模式下会有问题,调试的时候是没问题的,我把版本换到5.8.4就没问题 @lizhuoyuan

joeyzhao1005 commented 6 months ago

遇到了,release模式下

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.

zhhal commented 4 months ago

522 测试可用

lizhuoyuan commented 4 months ago

final TextStyle style = TextStyle( fontSize: 10.sp, ); 这个放的位置不对

HusseinReda97pro commented 3 months ago

I faced the same issue (xx.sp return 0), In my case, this was because I used it in static variables, which try to calculate before screenutil initiated, so my solution Is not to use .sp in static variables instead make a class and initialize one instance from it to be used throw the app, and initiated it in screenutil builder, this fix the issue with me

mozomig commented 2 months ago

you can use this solution for hack 5.9.0 version https://github.com/OpenFlutter/flutter_screenutil/issues/558#issuecomment-2047043378