栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用MediaQuery为Flutter中的文本设置scaleFactor?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用MediaQuery为Flutter中的文本设置scaleFactor?

您可以解决将

Text
小部件包装到
Flexible
以避免溢出的问题。我把maxLines 1放到Fade上看:

          new Row(       mainAxisAlignment: MainAxisAlignment.spaceBetween,       children: <Widget>[         Flexible(child: new Text(  "Account Name: Let's Flutter all day long till down with fancy User Interface",  maxLines: 1,  style: new TextStyle(      fontSize: myTextSize, color: Colors.black54),  overflow: TextOverflow.fade,),         ),         new Text("109.65",style: new TextStyle(    fontSize: myTextSize,    fontWeight: FontWeight.bold,    color: Colors.black),overflow: TextOverflow.fade,         ),       ],     ),

我添加了一个全局变量:

  var myTextSize = 12.0;

您也可以使用

LayoutBuilder
来获取设备的
maxHeight
maxWidth
,之后您可以像以下示例一样更改文本大小:

  var myTextSize = 12.0;  return LayoutBuilder(builder: (context, boxConstraints) {        print(boxConstraints.maxHeight);        if (boxConstraints.maxHeight <= 667.0){ myTextSize = 10.0;        }        return Container(          child: new ListTile( trailing: new Icon(Icons.chevron_right), onTap: () {}, title: new Row(   mainAxisAlignment: MainAxisAlignment.spaceBetween,   children: <Widget>[     new Text(       "My Account Details:",       style: new TextStyle(fontSize: 14.0,fontWeight: FontWeight.bold,color: Colors.black),       overflow: TextOverflow.fade,     ),   ], ), subtitle: new Column(   children: <Widget>[     new Row(       mainAxisAlignment: MainAxisAlignment.spaceBetween,       children: <Widget>[         new Text("Hello Flutter",style: new TextStyle(    fontSize: myTextSize, color: Colors.black54),overflow: TextOverflow.fade,         ),         new Text("Today is **************",style: new TextStyle(    fontSize: myTextSize, color: Colors.black54),overflow: TextOverflow.fade,         ),       ],     ),     new Row(       mainAxisAlignment: MainAxisAlignment.spaceBetween,       children: <Widget>[         new Text("Name",style: new TextStyle(    fontSize: myTextSize, color: Colors.black54),overflow: TextOverflow.fade,         ),         new Text("Dart",style: new TextStyle(    fontSize: myTextSize, color: Colors.black54),overflow: TextOverflow.fade,         ),       ],     ),     new Row(       mainAxisAlignment: MainAxisAlignment.spaceBetween,       children: <Widget>[         new Text("Surname",style: new TextStyle(    fontSize: myTextSize, color: Colors.black54),overflow: TextOverflow.fade,         ),         new Text("Flutter",style: new TextStyle(    fontSize: myTextSize,    fontWeight: FontWeight.bold,    color: Colors.black),overflow: TextOverflow.fade,         ),       ],     ),     new Row(       mainAxisAlignment: MainAxisAlignment.spaceBetween,       children: <Widget>[         Flexible(child: new Text(  "Account Name: Let's Flutter all day long till down with fancy User Interface",  maxLines: 1,  style: new TextStyle(      fontSize: myTextSize, color: Colors.black54),  overflow: TextOverflow.fade,),         ),         new Text("109.65",style: new TextStyle(    fontSize: myTextSize,    fontWeight: FontWeight.bold,    color: Colors.black),overflow: TextOverflow.fade,         ),       ],     ),   ], ),          ),        );      });


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418481.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号