flutter_screenutil icon indicating copy to clipboard operation
flutter_screenutil copied to clipboard

刚启动时 .sp 算出来是0

Open NullCrazy opened this issue 1 year ago • 10 comments

作者你好,在使用最新版本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")); } } `

NullCrazy avatar Oct 27 '23 13:10 NullCrazy

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

github-actions[bot] avatar Nov 27 '23 01:11 github-actions[bot]

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

SkyOfFeather avatar Dec 07 '23 06:12 SkyOfFeather

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

lizhuoyuan avatar Jan 05 '24 03:01 lizhuoyuan

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

M1sakii avatar Jan 09 '24 01:01 M1sakii

遇到了,release模式下

joeyzhao1005 avatar Jan 10 '24 10:01 joeyzhao1005

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

github-actions[bot] avatar Feb 10 '24 01:02 github-actions[bot]

#522 测试可用

zhhal avatar Feb 20 '24 02:02 zhhal

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

lizhuoyuan avatar Mar 07 '24 06:03 lizhuoyuan

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

HusseinReda97pro avatar Apr 05 '24 08:04 HusseinReda97pro

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

mozomig avatar Apr 11 '24 14:04 mozomig