【问题标题】:How to dynamically change text size inside a card?如何动态更改卡片内的文字大小?
【发布时间】:2021-01-02 08:08:50
【问题描述】:

我有一个表格,里面填满了改变了的行数和列数。

我想将每张卡片内的文字大小更改为最大可能的大小,这样单词仍然可以舒适地阅读。

卡片内的文字每次都会变化。

谢谢。

  class GameCardButton extends StatelessWidget {   final String word;  final Color cardColor;

  GameCardButton({@required this.word, this.cardColor});

  @override   Widget build(BuildContext context) {
    return Expanded(
      child: MaterialButton(
        //TODO: implement onPressed
        onPressed: () {},
        color: Colors.white,
        shape: RoundedRectangleBorder(
          side: BorderSide(color: Colors.teal),
        ),
        child: Text(
          word,
          textAlign: TextAlign.center,
          style: TextStyle(
            fontSize: 15.0,
          ),
        ),
      ),
    );   } }

【问题讨论】:

  • auto_size_text 有一些选项可以做我认为你想要的。
  • 是的,我试过了,但我希望所有单词的大小都一样。
  • 您是否使用了group 选项?
  • 如果空间更小,文本更长,那么你怎么能有相同的大小?

标签: android ios flutter dart mobile


【解决方案1】:

像这样包装Text 小部件:

Row(
  children: [
    Expanded(
      child: FittedBox(
        child: Text(
          word,
          textAlign: TextAlign.center,
        ),
      ),
    ),
  ],
)

【讨论】:

  • 谢谢,现在每张卡片都填上了不同大小的文字,有没有办法为所有文字设置一个大小?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-22
  • 2023-04-07
  • 2021-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-03
相关资源
最近更新 更多