Skip to content

Conversation

@bariskodas
Copy link
Member

@bariskodas bariskodas commented Jan 29, 2026

feat: Key Interaction Control (Enabled Keys Whitelist)

Summary

This PR implements a robust key interaction control system based on a whitelist approach. It introduces enabledKeys to VirtualKeyboardController, allowing developers to restrict keyboard input to a specific set of keys.

🚀 Features & Changes

API Refactor (Based on Feedback)

  • Moved Logic to Controller: The disabledKeys parameter was removed from the widget. Instead, enabledKeys (Set<VirtualKeyboardKey>?) is now a property of VirtualKeyboardController.
  • Whitelist Logic:
    • null: All keys are enabled (default).
    • Set<...>: Only keys in the set are interactive. Use this to restrict input (e.g. for a game or validation).
  • Special Key Support: Special keys (Enter, Backspace) can now be controlled via this API, offering full flexibility.

🛠 Implementation Details

  • Overlay Protection: Added logic to ensuring the key overlay (popup) is hidden immediately if a key becomes disabled while being pressed, preventing "stuck" UI states.
  • Type Safety: Used Set<VirtualKeyboardKey> to ensure type safety and eliminate string parsing overhead during render.
  • Theming: Retained the previous theming support (disabledBackgroundColor, disabledForegroundColor) to visually distinguish disabled keys.

Verification

  • Static Analysis: Passed dart analyze.
  • Manual Testing: Verified "Restrict Keys" demo in the example app.
  • Edge Case: Verified overlay hides when key is disabled during press.

Usage Example

final controller = VirtualKeyboardController(
  layout: EnglishQwertyKeyboardLayout(),
  onKeyPress: (key) => ...,
  // Only enable specific keys. All others will be disabled.
  enabledKeys: {
    VirtualKeyboardKey.a,
    VirtualKeyboardKey.b,
    VirtualKeyboardKey.backspace,
  },
);

@bariskodas
Copy link
Member Author

@orkun1675 could you review? ⚡️

…n `VirtualKeyboardController` for key restriction.
@bariskodas bariskodas requested a review from orkun1675 January 29, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants