virtual_keyboard.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'package:xterm/xterm.dart';
  3. class VirtualKeyboardView extends StatelessWidget {
  4. const VirtualKeyboardView(this.keyboard, {super.key});
  5. final VirtualKeyboard keyboard;
  6. @override
  7. Widget build(BuildContext context) {
  8. return AnimatedBuilder(
  9. animation: keyboard,
  10. builder: (context, child) => ToggleButtons(
  11. children: [Text('Ctrl'), Text('Alt'), Text('Shift')],
  12. isSelected: [keyboard.ctrl, keyboard.alt, keyboard.shift],
  13. onPressed: (index) {
  14. switch (index) {
  15. case 0:
  16. keyboard.ctrl = !keyboard.ctrl;
  17. break;
  18. case 1:
  19. keyboard.alt = !keyboard.alt;
  20. break;
  21. case 2:
  22. keyboard.shift = !keyboard.shift;
  23. break;
  24. }
  25. },
  26. ),
  27. );
  28. }
  29. }
  30. class VirtualKeyboard extends TerminalInputHandler with ChangeNotifier {
  31. final TerminalInputHandler _inputHandler;
  32. VirtualKeyboard(this._inputHandler);
  33. bool _ctrl = false;
  34. bool get ctrl => _ctrl;
  35. set ctrl(bool value) {
  36. if (_ctrl != value) {
  37. _ctrl = value;
  38. notifyListeners();
  39. }
  40. }
  41. bool _shift = false;
  42. bool get shift => _shift;
  43. set shift(bool value) {
  44. if (_shift != value) {
  45. _shift = value;
  46. notifyListeners();
  47. }
  48. }
  49. bool _alt = false;
  50. bool get alt => _alt;
  51. set alt(bool value) {
  52. if (_alt != value) {
  53. _alt = value;
  54. notifyListeners();
  55. }
  56. }
  57. @override
  58. String? call(TerminalKeyboardEvent event) {
  59. return _inputHandler.call(event.copyWith(
  60. ctrl: event.ctrl || _ctrl,
  61. shift: event.shift || _shift,
  62. alt: event.alt || _alt,
  63. ));
  64. }
  65. }