0

ATTENTION: Windows-Development here.

I want to use a virtual keyboard (on screen). I can not rely on a hardware-keyboard.

My goal is to securely get any TextEditingController if I e.g. tap on a TextFormField so I can use it in my virtual keyboard (I use this plugin).

Currently my VirtualKeyboard is wrapped in a Stack as a Positioned and only shown if a Focus-change has been detected. This already works:

Focus(
    onFocusChange: ((value) {
      BlocProvider.of<KeyboardCubit>(context).setShow(value);
    }),
    child: Stack(...),
)

But I'm stuck on the part to get the TextEditingController. I do not want to add custom code for every TextFormField. Flutter achieves it somehow when pressing on something that may be focusable, so why can't I?

Maybe I am missing something. I am glad to hear your opinions.

Best regards.

Alternative Question: Is there any good Virtual Keyboard plugin that handles this use case safely?

Marwin Lebensky
  • 270
  • 1
  • 2
  • 16
  • 1
    cannot you create a custom widget that creates `FocusNode` / `TextEditingController` and builds `TextFormField` with those two? – pskink Feb 17 '22 at 17:16
  • @pskink probably yes, but I don't want to replace every default widget with a custom widget. I think that flutter solves this somehow, and i **really** want to find out if I can do it without wrapping default widgets in some custom widgets. – Marwin Lebensky Feb 17 '22 at 23:52
  • If you can detect when a specific TextFormField has focus, you should know its controller. – dante Feb 18 '22 at 02:29
  • @dante i can detect that there is focus but not where it comes from. Or at least i do not know. Maybe you do? – Marwin Lebensky Feb 18 '22 at 11:08
  • I found something from the `flutter_test`: https://api.flutter.dev/flutter/flutter_test/simulateKeyDownEvent.html Maybe we can make use of that? – Marwin Lebensky Feb 18 '22 at 11:09
  • see `FocusManager.instance.primaryFocus` but still you have to assign unique `FocusNode` and `TextEditingController` for every `TextFormField` - how would you do that if not by setting `focusNode` and `controller` properties? – pskink Feb 18 '22 at 11:30
  • @pskink Flutter creates a `TextEditingController` if none is provided: "If null, this widget will create its own [TextEditingController] and (...)" Line 259 in `text_form_field.dart`. Think about it, if flutter can handle it implicitly, why can't i expose a currently selected/attached `TextEditingController`/`Node`? I want to know if it is possible – Marwin Lebensky Feb 18 '22 at 11:38

0 Answers0