unicode - 如何在 Flutter 中组合 unicode 字符?

标签 unicode flutter

我需要在其他一些字符(如“2”或“x”)上显示组合上划线字符 (unicode U+0305)。

https://www.fileformat.info/info/unicode/char/0305/index.htm

有没有办法在 Dart 中实现这一点?

提前致谢。

最佳答案

您可以通过将 unicode 放在字母后面来组合:

String overlined = 'O\u{0305}V\u{0305}E\u{0305}R\u{0305}';

print(overlined);  // Output: O̅V̅E̅R̅ 

一个更动态的版本(具有简单的逻辑)是:

void main() {
  String overlined = overline('I AM AN OVERLINED TEXT');

  print(overlined);  // Output: I̅ A̅M̅ A̅N̅ O̅V̅E̅R̅L̅I̅N̅E̅D̅ T̅E̅X̅T̅
}

String overline(String text) {
  return text.split('').map((String char) {
    if (char.trim().isEmpty)
      return char;
    else
      return '$char\u{0305}';
  }).join();
}

但是,这非常有限。更好的方法是使用 Flutter 的 Textstyle 属性来这样做:

const Text(
  'OVER',
  style: TextStyle(decoration: TextDecoration.overline),
);

关于unicode - 如何在 Flutter 中组合 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55996657/

相关文章:

python - 'unicode' 对象没有属性 'replace'

html - 检查页面上字符的视觉存在?

flutter - TabBarView中具有WebSockets流的Streambuilder:错误状态:流已被监听

flutter - 在 Flutter 中添加 OverlayEntry

dart - Flutter:如何访问子页面中的 ScopeModel 属性

dart - 从毫米计算逻辑像素

objective-c - 网页内容问题

python - 在 python 中,为什么调用字符串 "X"会以 ASCII 显示它,而调用 "print X"将其显示为 unicode ?

unicode - 如何从 .t​​xt 文件中删除 <96>

Flutter:具有多个命名路由的flutter_page_transition不起作用