flutter_screenutil
flutter_screenutil copied to clipboard
刚启动时 .sp 算出来是0
作者你好,在使用最新版本5.9.0的时候,android release模式下 ,应用刚启动的时候设置 xx.sp,得到的字体大小一直是0,换之前的版本没有这个问题!大致代码如下:
` class MyHomePageState extends State<MyHomePage> { @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<HomePage> createState() => _HomePageState(); }
class _HomePageState extends State<HomePage> { final TextStyle style = TextStyle( fontSize: 10.sp, );
@override Widget build(BuildContext context) { print(">>>>>>${style.fontSize}"); return const Center(child: Text("test")); } } `
This issue is stale because it has been open for 30 days with no activity.
5.9.0问题挺多,但没人回复,奇怪
我把你这段代码放到了example中运行,没发现问题啊
在release模式下会有问题,调试的时候是没问题的,我把版本换到5.8.4就没问题 @lizhuoyuan
遇到了,release模式下
This issue is stale because it has been open for 30 days with no activity.
#522 测试可用
final TextStyle style = TextStyle( fontSize: 10.sp, ); 这个放的位置不对
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
you can use this solution for hack 5.9.0 version https://github.com/OpenFlutter/flutter_screenutil/issues/558#issuecomment-2047043378