How to combine unicode characters in Flutter?

2,271

You can combine by placing the unicode right after the letter:

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

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

A more dynamic version (with simplistic logic) would be:

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

However, this is pretty much limited. A better approach would be using the style property of Flutter's Text to do so:

const Text(
  'OVER',
  style: TextStyle(decoration: TextDecoration.overline),
);
Share:
2,271
Gorges
Author by

Gorges

Updated on December 11, 2022

Comments