getPinyinTone static method

int getPinyinTone(
  1. String syllable
)

Detects a tone of a single syllable where 5 means neutral tone it works for one syllable only. If you need to detect tones of a sentence, use getPinyinTones() instead

Implementation

static int getPinyinTone(String syllable) {
  final tones = [
    ['ā', 'ē', 'ō', 'ī', 'ū', 'ǖ'],
    ['á', 'é', 'ó', 'í', 'ú', 'ǘ'],
    ['ǎ', 'ě', 'ǒ', 'ǐ', 'ǔ', 'ǚ'],
    ['à', 'è', 'ò', 'ì', 'ù', 'ǜ'],
  ];
  for (int i = 0; i < tones.length; i++) {
    final list = tones[i];
    if (list.any((s) => syllable.contains(s))) {
      return i + 1;
    }
  }
  return 5;
}