flutter_screenutil icon indicating copy to clipboard operation
flutter_screenutil copied to clipboard

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

Open runchen0518 opened this issue 5 years ago • 3 comments

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));

runchen0518 avatar Dec 15 '20 14:12 runchen0518

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

lizhuoyuan avatar Dec 16 '20 04:12 lizhuoyuan

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.

runchen0518 avatar Dec 17 '20 07:12 runchen0518

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

lizhuoyuan avatar Dec 21 '20 10:12 lizhuoyuan