Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NullCrazy opened this issue Oct 27, 2023 · 10 comments
Open

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

NullCrazy opened this issue Oct 27, 2023 · 10 comments

Comments

@NullCrazy
Copy link

NullCrazy commented Oct 27, 2023

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

Copy link

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

@github-actions github-actions bot added the stale label Nov 27, 2023
@SkyOfFeather
Copy link

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

@github-actions github-actions bot removed the stale label Dec 8, 2023
@lizhuoyuan
Copy link
Collaborator

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

@M1sakii
Copy link

M1sakii commented Jan 9, 2024

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

@joeyzhao1005
Copy link

joeyzhao1005 commented Jan 10, 2024

遇到了,release模式下

Copy link

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

@github-actions github-actions bot added the stale label Feb 10, 2024
@zhhal
Copy link

zhhal commented Feb 20, 2024

#522 测试可用

@github-actions github-actions bot removed the stale label Feb 21, 2024
@lizhuoyuan
Copy link
Collaborator

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

@HusseinReda97pro
Copy link

HusseinReda97pro commented Apr 5, 2024

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
Copy link

mozomig commented Apr 11, 2024

you can use this solution for hack 5.9.0 version #558 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants