Shortcut Keyboard For TextField Widget

In this post, we will add a shortcut keyboard for TextField widget in Flutter app.


Let’s say you have a user input field where users type in certain data. If user has to type a certain word or character frequently, you might want to provide a shortcut to such texts.

For an example, users might have to frequently type in numbers such as 100, 200, 500 etc. on a TextField. In this post, we will learn to create a shortcut keyboard just for that purpose.

We are going to add this feature on our Expense Manager app continuing from previous post. At the end of this post, we will have achieved the following:

Shortcut Keyboard For TextField In Flutter
Shortcut Keyboard For TextField In Flutter


Adding A TextField For Numbers Input

In the add_expense.dart file below the category selector, add a Column widget. Inside it’s children we first add a TextField that allows users to enter numbers.

TextField For Amount
TextField For Amount

Create A Shortcut Keyboard Widget

Next, we create a shortcut keyboard Widget.

Here, we have created a horizontally scrollable ListView that has a list of FlatButton widgets for different numbers.

Now, add this widget below the previous TextField.

Shortcut Keyboard Widget 1
Shortcut Keyboard Widget 1

A shortcut keyboard widget is created below our TextField.

However, there are still a few of issues that we want to take care of here:

  • Show shortcut keyboard right on top of device keyboard.
  • Show shortcut keyboard only when TextField is in focus.
  • Handle Shortcut key press event.

Position Shortcut Keyboard On Top Of Keyboard

In order to make sure our shortcut keyboard shows right on top of regular keyboard, we will make use of Expanded widget.

Here we have wrapped both the Column and TextField container in Expanded widgets.

Become A Flutter Expert With This Course

Check If TextField Is In Focus

Now, we need to check if our TextField is in focus before showing this shortcut keyboard. For this, we will make use of the FocusNode which will enable us to obtain the keyboard focus on TextField widget.

Create a FocusNode and add a listener to the focus change event.

Here, we have created a FocusNode and assigned it to the TextField‘s focusNode property. Then we set the value of _showKeyboard to true when the TextField has focus.

Handle Keyboard Shortcut Key Press

Finally, we need to implement the short cut key press events. For this, first add a TextEditingController for the TextField.

Update the onPressed event for short key button.

Working Shortcut Keyboard
Working Shortcut Keyboard

Great, we now have a working shortcut keyboard for our TextField widget.

Update Keyboard Cursor Position Of TextField

As you might have noticed from the image above, although the text in the TextField is being updated, the cursor position isn’t correct. The cursor should move to the end of line. But it is staying at the beginning position of the text inside the TextField.

In order to fix this, we need to reset the values of TextSelection property of the TextEditingController.

Here, we ensure that the selection is set to the last position of the text.


In this post, we learned to create a shortcut keyboard for TextField widget in flutter. The shortcut keyboard was made visible only when the TextField was set in focus. It was positioned on top of the device keyboard. Then the TextField‘s value was updated on the shortcut key press. We also learned to set the cursor position of TextField programmatically.

Learn More About Working With TextField Widget

About the author