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

如何使用MediaQuery为Flutter中的文本设置scaleFactor?,第1张

如何使用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,         ),       ],     ),   ], ),          ),        );      });


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5051777.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存