首页 > 解决方案 > 如何动态更改卡片内的文字大小?

问题描述

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

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

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

谢谢你。

  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,
          ),
        ),
      ),
    );   } }

好的例子 不好的例子

标签: androidiosflutterdartmobile

解决方案


像这样包装Text小部件:

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


推荐阅读