【问题标题】:How to resize test based on screen size in Flutter?如何在 Flutter 中根据屏幕大小调整测试大小?
【发布时间】:2021-10-11 20:24:52
【问题描述】:

我正在 Flutter 上开发一个应用程序,我的主页中有一个包含两个文本小部件的列。问题是在手机上,文字大小正常,但在平板电脑上,文字太小看不清。您能否建议一种根据屏幕尺寸动态放大文本的方法?

小部件:

Column(
    children: [
      Text(
        widget.label,
        style: TextStyle(
            fontFamily: 'Roboto',
            color: Colors.white,
            fontWeight: FontWeight.bold),
      ),
      Text(
        widget.description,
        style: TextStyle(
            fontFamily: 'Roboto',
            color: Colors.white,
            fontWeight: FontWeight.w100),
      )
    ],
  ),

谢谢

【问题讨论】:

    标签: android flutter dart mobile


    【解决方案1】:

    这个包在这里:

    auto_size_text , https://pub.dev/packages/auto_size_text

    会有帮助的。

    【讨论】:

      【解决方案2】:

      你可以有两种方法:

      1. 使用auto_size_text
      2. 使用MediaQuery.of(context).size.widthMediaQuery.of(context).size.height 访问屏幕的宽度和高度,然后使用它们调整SizedBox 的大小并将您的文本作为FittedBox(child:YourTextWidget) 传递给此小部件。例如:
      SizedBox(
      width: 0.5 * screenWidth, // change 0.5 to whatever your want
      child:FittedBox(
      child: Text("Your Text")
      ))
      

      【讨论】:

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