flutter - 如何在单个文本中包含多种字体

标签 flutter dart

我有一个 pdf 文件中的阿拉伯语文本。当我将文本复制到 Text Widget 时,它会变成奇怪的字符。当我检查 pdf 文件属性时,我发现它使用 HQPB1、HQPB2、HQPB3、HQPB4 字体,所以我将所有这些字体导入到我的 pubsec.yaml 文件中。问题是我一次只能使用这 4 种字体中的一种,但 pdf 文件同时使用所有这 4 种字体。
this is the original text from pdf
when I added  HQPB1.ttf only
when I added HQPB2.ttf only
所以我想将所有这 4 种字体都包含在一个文本中,以便在需要时应该像 pdf 一样使用每个单独的字体。

最佳答案

RichText(
  text: TextSpan(
    children: <TextSpan>[
      TextSpan(text: 'Hello ', style: TextStyle(fontFamily: "Serif", fontSize: 30, color: Colors.black)),
      TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue, fontSize: 30)),
      TextSpan(text: ' world!', style: TextStyle(fontFamily: "Roboto", fontSize: 30, color: Colors.red)),
    ],
  ),
)

输出:

enter image description here

关于flutter - 如何在单个文本中包含多种字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57462801/

相关文章:

android - 最近更新后,pug get 无法正常工作。有任何想法吗?

flutter - 如何在 dart/flutter 中继承静态方法?

android-studio - 运行命令 "flutter run"时出错

dart - 如何在 flutter 小部件中使用条件语句/三元

flutter - Flutter和Redux

flutter - 底部导航栏全白,如何解决?

node.js - 用 nodejs 编码的 jwt token 解码用 flutter(dart) 制作

flutter - 如何正确填充带有点击效果的IconButton?

firebase - Flutter Firestore Geo 查询距我所在位置一定距离

dart - 运行发布安装。请确保 Git 已正确安装。苹果操作系统