android-studio - 我如何格式化(粗体)文本中的单词?

标签 android-studio dart flutter flutter-layout

在下面的代码中,我想将“$_counter”的值设为粗体。如何实现?

new Text(
  'You have pushed the button $_counter time${_counter > 1
      ? 's'
      : ''}',
  style: new TextStyle(fontSize: fontSize),
  textAlign: TextAlign.center,
),

我希望输出是这样的:

您已按下按钮 2

最佳答案

你必须使用 RichTextfor

new RichText(
textAlign: TextAlign.center,
          text: new TextSpan(
            style: TextStyle(color: Colors.black),
            children: <TextSpan>[
              new TextSpan(text: 'You have pushed the button '),
              new TextSpan(text: '$_counter', style: new TextStyle(fontWeight: FontWeight.bold)),
              new TextSpan(text: ' time!'),
            ],
          ),
        )

enter image description here

关于android-studio - 我如何格式化(粗体)文本中的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319174/

相关文章:

android - minSdkVersion 低于设备 API 版本的 INSTALL_FAILED_OLDER_SDK

java - 无法初始化 Parse SDK 测试

firebase - Flutter:Java 使用或覆盖已弃用的 API

flutter 我正在使用 gridview.count,但我无法设置高度

java - 尝试将变量传递给 BroadcastReceiver 类,但只发生一次

java - 拥有多个 WebView 或导入 Java 库

flutter - 使用 setState 时 WidgetsBinding.instance.addPostFrameCallback 被多次调用

java - Flutter Java android从/app_flutter文件夹中的文件获取数据

android - 在 Dismissible Widget 上禁用关闭方向

flutter - Sliverappbar与主体中的内容重叠( flutter )