【问题标题】:Adjust textSize, widget sizes based on the screen根据屏幕调整 textSize、widget 大小
【发布时间】:2020-06-05 15:04:20
【问题描述】:

我正在为移动设备和安卓电视(48 英寸电视)开发一个应用程序。我使用MediaQuery 调整字体大小和小部件大小。有没有更好的方法来做这些事情?

static double width(BuildContext context) => MediaQuery.of(context).size.width;

height: height * 1 / 32,

textSize: height * 1 / 32

Line > 容器小部件

CustomLine(
              width: width * (1 / 8),
              height: height * (1 / 512),
              color: Palette.white,
            ),

【问题讨论】:

标签: flutter dart


【解决方案1】:

这取决于您是否想要带或不带安全区域的大小:

https://stackoverflow.com/a/57237870/12937274

你也可以试试:

 import 'dart:ui';

window.physicalSize;

【讨论】:

    【解决方案2】:

    我从来没有为这样的屏幕开发过任何东西,但我过去曾使用auto_size_text package 轻松地根据可用空间自动调整文本大小,而且效果非常好。使用此软件包,您无需为每个 Text 显式处理尺寸。

    另一种方法是使用LayoutBuilder class 获取Text 小部件周围的可用空间,并自行处理适当的大小。

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 2015-07-16
      相关资源
      最近更新 更多