【问题标题】:how to make flutter app font responsive for tablet?如何使 Flutter 应用程序字体响应平板电脑?
【发布时间】:2021-08-16 00:56:42
【问题描述】:

**flutter app需要对tablet做出响应,if怎么写 ---------------------- 尺寸条件你能帮我吗**

Widget build(BuildContext context) {
        var screenSize = MediaQuery.of(context).size;
        return WillPopScope(
          onWillPop: _onWillPop,
          child: Scaffold(
            backgroundColor: Constant.BLACK_COLOR,
            appBar: AppBar(
              centerTitle: true,


    ******this is my example code , i need to make bigger font only in tablet ******

我尝试过sizer,但我还是个新手,如果你知道,请帮助我

【问题讨论】:

标签: flutter responsive


【解决方案1】:

您可以使用auto_size_text 包来做到这一点:

Container(
  child: ConstrainedBox(
    constraints: BoxConstraints(
      minWidth: MediaQuery.of(context).size.width,
      maxWidth: MediaQuery.of(context).size.width,
      minHeight: MediaQuery.of(context).size.height,
      maxHeight: MediaQuery.of(context).size.height,
    ),
    child: AutoSizeText(
      "yourText",
      style: TextStyle(fontSize: 16.0),
    ),
  ),
);

您可以相应地更改约束,这将使您的应用总体上更具响应性。

【讨论】:

    【解决方案2】:

    你可以使用flutter_screenutil

       Text(
         '16sp, will not change with the system.',
          style: TextStyle(
            color: Colors.black,
            fontSize: 16.sp, // this will make font responsive
          ),
        ),
    

    或者您可以使用以下代码识别设备类型

      static bool isMobile(BuildContext context) =>
          MediaQuery.of(context).size.width < 650;
    
      static bool isTablet(BuildContext context) =>
          MediaQuery.of(context).size.width < 1100 &&
          MediaQuery.of(context).size.width >= 650;
    
      static bool isDesktop(BuildContext context) =>
          MediaQuery.of(context).size.width >= 1100;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      相关资源
      最近更新 更多