diff --git a/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard.dart b/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard.dart index ece803d..72393f2 100644 --- a/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard.dart +++ b/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard.dart @@ -407,6 +407,22 @@ class _OnscreenKeyboardState extends State setState(() => _mode = modes[(i + 1) % modes.length]); } + @override + void setModeNamed(String modeName) { + if (_mode == modeName) return; + + if (_layout.modes.containsKey(modeName)) { + setState(() { + _mode = modeName; + }); + } else { + debugPrint( + "OnScreenKeyboard: Keyboard mode '$modeName' " + 'not found on the KeyboardLayout.', + ); + } + } + final GlobalKey _keyboardKey = GlobalKey(); /// Alignment of the keyboard diff --git a/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard_controller.dart b/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard_controller.dart index 84f8f09..160650b 100644 --- a/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard_controller.dart +++ b/packages/flutter_onscreen_keyboard/lib/src/onscreen_keyboard_controller.dart @@ -49,4 +49,9 @@ abstract interface class OnscreenKeyboardController { /// Calling this method switches the current mode to the next one, /// wrapping around to the first mode when the end is reached. void switchMode(); + + /// Sets the keyboard mode to the one specified by [modeName]. + /// + /// The [modeName] must exist in the current [KeyboardLayout.modes]. + void setModeNamed(String modeName); }