getCurrentInputSource function
Gets the current input source as an opaque token.
Returns a token identifying the currently active keyboard input source. Save it as-is and later restore it with setInputSource.
Treat the value as opaque: it is platform-specific and its format is an implementation detail. Do not parse, compare, or construct it yourself. The examples below are illustrative only.
The format is unchanged from 2.x, so a token your app saved before upgrading still restores afterwards.
Platform Support
- macOS: Returns input source ID (e.g., "com.apple.keylayout.ABC", "com.apple.inputmethod.Korean.2SetKorean")
- Windows: Returns keyboard layout and IME state in format "KLID:conversion:sentence" (e.g., "00000412:1:0" for Korean keyboard in Hangul mode)
- Other platforms: Returns
null
Returns
- Input source ID string on supported platforms
nullon unsupported platforms or if unable to get input source
Example
// Save current keyboard before switching to English
final savedInputSource = await getCurrentInputSource();
await setEnglishKeyboard();
// Later, restore the previous keyboard
if (savedInputSource != null) {
await setInputSource(savedInputSource);
}
See also:
- setInputSource to restore a saved input source
- setEnglishKeyboard to switch to English mode
Implementation
Future<String?> getCurrentInputSource() async {
if (!platformSupport.isSupported) return null;
return FlutterImePlatform.instance.getCurrentInputSource();
}