A simple package for dispaying virtual keyboards on a devices like kiosks and ATMs. The library is written in Dart and has no native code dependancy.
V keyboard provides a core set of functionality to display onscreen virtual keyboards. Managing the events sould be done on the project level.
Flutter widget to show virtual keyboards.
// Keyboard Type: Can be Numeric or Alphanumeric.
VKeyboardType type
// Callback for Key press event. Called with pressed `Key` object.
Function onKeyPress;
// V keyboard height. Default is 300.
double height;
// Color for key texts and icons.
Color textColor;
// Font size for keyboard keys.
double fontSize;;
// Only Caps letters enabled.
bool alwaysCaps;;
enum of Available V Keyboard Types.
// Numeric only.
VKeyboardType.Numeric
// Alphanumeric: letters`[A-Z]` + numbers`[0-9]` + `@` + `.`.
VKeyboardType.Alphanumeric
V Keyboard key.
// The text of the key.
String text
// The capitalized text of the key.
String capsText;
// Action or String
VKeyboardKeyType keyType;
// Action of the key.
VKeyboardKeyAction action;
Type for virtual keyboard key.
// Can be an action key - Return, Backspace, etc.
VKeyboardKeyType.Action
// Keys that have text values - letters, numbers, comma ...
VKeyboardKeyType.String
/// V keyboard actions.
enum VKeyboardKeyAction { Backspace, Return, Shift, Space }
// Wrap the keyboard with Container to set background color.
Container(
// Keyboard is transparent
color: Colors.deepPurple,
child: VKeyboard(
// Default height is 300
height: 350,
// Default is black
textColor: Colors.white,
// Default 14
fontSize: 20,
// [A-Z, 0-9]
type: VKeyboardType.Alphanumeric,
// Callback for key press event
onKeyPress: _onKeyPress),
)
Container(
// Keyboard is transparent
color: Colors.red,
child: VKeyboard(
// [0-9] + .
type: VKeyboardType.Numeric,
// Callback for key press event
onKeyPress: (key) => print(key.text)),
)
Container(
color: Colors.deepPurple,
child: VKeyboard(
height: keyboardHeight,
textColor: Colors.white,
fontSize: 20,
builder: _builder,
type: VKeyboardType.Numeric,
onKeyPress: _onKeyPress),
)
/// Builder for keyboard keys.
Widget _builder(BuildContext context, VKeyboardKey key) {
Widget keyWidget;
switch (key.keyType) {
case VKeyboardKeyType.String:
// Draw String key.
keyWidget = _keyboardDefaultKey(key);
break;
case VKeyboardKeyType.Action:
// Draw action key.
keyWidget = _keyboardDefaultActionKey(key);
break;
}
return keyWidget;
}
// Just local variable. Use Text widget or similar to show in UI.
String text;
/// Fired when the virtual keyboard key is pressed.
_onKeyPress(VKeyboardKey key) {
if (key.keyType == VKeyboardKeyType.String) {
text = text + (shiftEnabled ? key.capsText : key.text);
} else if (key.keyType == VKeyboardKeyType.Action) {
switch (key.action) {
case VKeyboardKeyAction.Backspace:
if (text.length == 0) return;
text = text.substring(0, text.length - 1);
break;
case VKeyboardKeyAction.Return:
text = text + '\n';
break;
case VKeyboardKeyAction.Space:
text = text + key.text;
break;
case VKeyboardKeyAction.Shift:
shiftEnabled = !shiftEnabled;
break;
default:
}
}
// Update the screen
setState(() {});
}
Original Creator
Improvement - [CODEBLOCK TEAM](https://codeblock.co.tz)