textToMorse function
Converts English text to Morse code. Throws an ArgumentError if any unsupported character is detected.
Implementation
String textToMorse(String text) {
final result = text.toUpperCase().split('').map((char) {
if (!_morseCodeMap.containsKey(char)) {
throw ArgumentError('Unsupported character: $char');
}
return _morseCodeMap[char] ?? '';
}).join(' ');
return result;
}