Android设备上的像素溢出-颤振

时间:2020-08-08 11:37:26

标签: android ios flutter

我是扑朔迷离的新手,我正尝试通过youtube视频了解更多信息。我遇到了一个视频,该视频为应用创建了入门屏幕。但是,当我运行提供的代码(粘贴在下面)时,尝试在android模拟器上运行时遇到以下错误:

enter image description here

我很好奇如何使它在android和ios上都能正常工作,因为我猜想每个设备上的可用大小都不一样,所以我想到了MediaQuery.of(context).size.height也许是最好的方法?如果有人可以帮助我解决这个问题,我将不胜感激。非常感谢。这是代码:

json.decode()

1 个答案:

答案 0 :(得分:1)

您正在寻找的是ScreenUtil。它根据屏幕比例调整窗口小部件的大小。 此处的文档:https://pub.dev/packages/flutter_screenutil

将flutter_screenutil软件包添加到您的pubspec文件中。

将其导入到ur dart文件中,然后像这样使用它:

import 'package:flutter_screenutil/flutter_screenutil.dart';

//inside build method
ScreenUtil.init(height: test_device_height, width: test_device_width, enableFontScaling:true);
//That's how you initialise it. Use font scaling to change the font size too!

//Use it in a widget like so:
return Container(
  height: ScreenUtil().setHeight(original_height),
  width: ScreenUtil().setWidth(original_width);
  child: Text("Hello World",
    style: TextStyle(
      fontSize: ScreenUtil().setSp(original_font_size),
      //This is how you set font size, 
      //or you'll get sizing problems with that too
    ),
  ),
);