android - 如何动态更改卡内的文本大小?

标签 android ios flutter dart mobile

我有一个表,其中填充了更改了的行数和列数。
我想将每张卡中的文本大小更改为最大可能的大小,以便单词仍然能够舒适地阅读。
卡内的单词每次都会更改。
谢谢。

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

最佳答案

这样包装Text小部件:

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

关于android - 如何动态更改卡内的文本大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63904024/

相关文章:

android - Gradle 依赖项 : Get latest snapshot from remote repo

android - 如何让用户(即他的位置)在谷歌地图中移动,其中用户的更新位置是从 MySql 获取的?

ios - 一次将所有 UI 元素快速连接到一个 socket

ios - 在 Logo 调整中显示 UIAlertView 或 UIViewController

iOS—NSDictionary 有 6 个键,显示 3

flutter - 当我已经为另一个函数进行了计算时,为什么不能将这些计算调用到我的构建中

android - 如何在android中绘制位图?

java - 尝试从数据库(android)获取数据时内存耗尽

flutter - Navigator.of(context).pop();使整个屏幕消失,而不是弹出窗口

flutter - Dart 类型转换动态扩展