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

It seems a bug, when you use sp in some special devices such as iPad. #180

Closed
runchen0518 opened this issue Dec 15, 2020 · 3 comments
Closed

Comments

@runchen0518
Copy link

runchen0518 commented Dec 15, 2020

Descriptions:
In general, a textview with 22sp text content, may be 30dp height in screen. But, when you put the textview into a constraint container which is 30dp height, the textview will be overflow.

It means, the value return of sp() function may be bigger in pads.

Devices:
Some abnormal screen rate devices, especially iPad.

image

Configs:
ScreenUtil.init(context, width: 375, height: 812, allowFontScaling: false);

Suggestions:
Further, i have a suggestion. Could you please give a public api such as getRadius(). We want to use it in some special cases, such as square widgets, or other round widgets.

A common scenario as i say, here is a square widget with a 16 side length. If i set ScreenUtil().setWidth(16) to the widget width, and in turn, i set ScreenUtil().setHeight(16) to the widget height. When the widget displayed on ipad screens, it will not be a square widget no more. It will become a rectangle widget because of the difference of height & width.

The implementation of getRadius() may be easy, you can get it from the min of adapted height and adapted width.
static num radius(num r) => min(ScreenUtil().setWidth(r), ScreenUtil().setHeight(r));

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Dec 16, 2020

The use of px for adaptation may indeed cause the problem you mentioned. In fact, I have considered using dp as the unit, but the size of the design draft can be set to dp, and px is more versatile, and some do not support dp, so I Delayed the plan.

My current experience is to try not to limit the size of the text, it may be helpful

Regarding your suggestion, I actually said: If you want a square, it is recommended to use setWidth for both width and height.
Do you still think you need radius? Or is there any other necessity to increase it

@runchen0518
Copy link
Author

The use of px for adaptation may indeed cause the problem you mentioned. In fact, I have considered using dp as the unit, but the size of the design draft can be set to dp, and px is more versatile, and some do not support dp, so I Delayed the plan.

My current experience is to try not to limit the size of the text, it may be helpful

Regarding your suggestion, I actually said: If you want a square, it is recommended to use setWidth for both width and height.
Do you still think you need radius? Or is there any other necessity to increase it

Emmm... I wanna to get a perfect solution of sp() .

I've already implemented the function getRadius(). And I think, we should use the min of adapted height and adapted width, otherwise, it'll be overflowed on some devices.

@lizhuoyuan
Copy link
Collaborator

lizhuoyuan commented Dec 21, 2020

you can try that:

v4.0.1
Two lines of text

                Container(
                  height: 32.h,
                  child: Text(
                    'My font size is 16sp on the design draft and will not change with the system.',
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 16.sp,
                    ),
                  ),
                ),

and I will add radius method on 4.0.2

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

2 participants