The original
Medium.com/flutterdevs…
code
Github.com/flutter-dev…
reference
- Pub. Dev/packages/ke…
The body of the
Learn how to customize the default keyboard in your Flutter application
Keyboard actions in Flutter
Android /IoS offers keyboards that don’t have buttons to hide the keyboard, which can be quite inconvenient for users. When our application has many textfields that need to display action keys and handle functions defined as fields on the toolbar. Keyboard actions are keys that indicate action on the current field when the user clicks on that field.
In this article, I’ll demonstrate how to display keyboard actions in an application using form input that contains fields. We’ll also implement a demo program and use the package Keyboard Action to demonstrate these features. I try to explain my project in a simple way
Brief introduction:
KEYBOARD_ACTION provides several packages to make your device’s keyboard customizable. Today, we’re going to talk about KEYBOARD Actions. There is a well-known problem in iOS that when we use the numeric input field it does not show the finish button inside/above the keyboard. As a result, keyboard manipulation offers a variety of features that help overcome the problems that users and developers are currently facing.
Pub. Dev/packages/ke…
Features:
- Complete keyboard buttons (you can customize buttons)
- Move up and down between text fields (can hide Settings)
nextFocus: false
). - Keyboard bar customization
- Custom footer widget below the keyboard bar
- The easy way to create your own keyboard
- You can use it on Android, iOS, or both
- Compatible with dialog boxes
Established projects:
Step 1: Use packaging
keyboard_actions | Flutter Package
Keyboard | Flutter Package
Add features to Android/iOS keyboards in a simple way. Because android /iOS provides keyboards..
pub.dev
Pub. Dev/packages/ke…
Add the YouTube player_iframe plugin to the dependencies of the pubspec.yaml file and then run the $flutter pub get command.
dependencies:
keyboard_actions: ^3.44.
Copy the code
Step 2: Import the package as
import 'package:keyboard_actions/keyboard_actions.dart';
Copy the code
Code Implementation:
Code implementation:
1. Create a new DART file called home_screen.dart. Folders to design the user interface and write the logic you want to implement in your project
2. I built long Forms in the Flutter Demo project and ran the application on Android. If we’re using an IOS device, it won’t show done done. On IOS, when we use the numeric entry field, on Android, the buttons in/above the keyboard won’t show up
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 8.0,
child: Container(
padding: EdgeInsets.only(left: 12),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Footer'),
controller: _customController,
focusNode: _nodeText6,
keyboardType: TextInputType._number_,
),
TextFormField(
decoration: InputDecoration(labelText: 'Input Number'),
focusNode: _nodeText1,
keyboardType: TextInputType._number_,
textInputAction: TextInputAction.next
),
TextFormField(
decoration: InputDecoration(
labelText: 'Custom cross Button'),
focusNode: _nodeText2,
keyboardType: TextInputType._text_,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Action'),
focusNode: _nodeText3,
keyboardType: TextInputType._number_,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Text without Done button'),
focusNode: _nodeText4,
keyboardType: TextInputType._text_,
),
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Toolbar Buttons'),
focusNode: _nodeText5,
keyboardType: TextInputType._number_,
),
],
),
),
),
),
);
Copy the code
3. Now, to add keyboard actions to your project, you need to wrap all textFormFields under Widget KeyboardAction, The Widget KeyboardAction requires the KeyboardActivesConfig configuration to add configuration on the keyboard.
return KeyboardActions(
tapOutsideBehavior: TapOutsideBehavior.translucentDismiss,
_//autoScroll: true,_ config: _buildConfig(context),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 8.0,
child: Container(
padding: EdgeInsets.only(left: 12),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Custom Footer'),
controller: _customController,
focusNode: _nodeText6,
keyboardType: TextInputType._number_,
),
Copy the code
4. Provides a feature that turns off the keyboard when we press anywhere but it on the device’s screen. So, we need to add this row
tapOutsideBehavior: TapOutsideBehavior.translucentDismiss,
Copy the code
5. We should initialize the FocusNode object assigned to the different text fields. Therefore, developers customize because it allows the keyboard to focus on the widget.
final FocusNode _nodeText1 = FocusNode();//Add In TextFormField TextFormField(
decoration: InputDecoration(
labelText: 'Input Number with Toolbar Buttons'),
focusNode: _nodeText1,
keyboardType: TextInputType._number_,
)
Copy the code
6. We will define KeyboardansConfig. The wrapper is an action bar for a single configuration keyboard. In KeyboardansConfig, we define the actions performed by the keyboard individually for each TextFormField according to your needs. We can customize the keyboard color, the color of the dividing line between the keyboard and the content, and display the focus between moving the input before/after the arrow.
KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.ALL,
keyboardBarColor: Colors._grey_[200],
keyboardSeparatorColor: Colors._redAccent_,
nextFocus: true,
actions: [
Copy the code
7. Now we will define the actions according to the requirements in the different TextFormFields.
actions: [
KeyboardActionsItem(
focusNode: _nodeText1,
),
Copy the code
8. To display input with custom footers in your application, you need to implement the following code in your KeyboardActionsItem, where we must pass TextController in the Text widget.
KeyboardActionsItem(
focusNode: _nodeText6,
footerBuilder: (_) => PreferredSize(
child: SizedBox(
height: 40,
child: Center(
child: Text(_customController.text),
)),
preferredSize: Size.fromHeight(40))),Copy the code
9. To display custom dialogs in your application, add this logic to the focus node specified in KeyboardActionsItem.
KeyboardActionsItem(
focusNode: _nodeText3,
onTapAction: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text("Show Custom Action"),
actions: <Widget>[
FlatButton(
child: Text("OK"), onPressed: () => Navigator._of_(context).pop(), ) ], ); }); },),Copy the code
When we run the application, we get a video of the output on the screen, as shown below, and the user can observe the output.
Conclusion:
In this article, I have briefly introduced the basic structure of the KeyboardAction package; You can modify this code as you choose, or use the package as you see fit. This is a small introduction to the keyboard custom user interaction from my side, which works using Flutter.
The elder brother of the © cat
-
ducafecat.tech/
-
github.com/ducafecat
-
Ducafecat WeChat group
-
B station space.bilibili.com/404904528
The issue of
Open source
GetX Quick Start
Github.com/ducafecat/g…
News client
Github.com/ducafecat/f…
Strapi manual translation
getstrapi.cn
Wechat discussion group Ducafecat
A series of collections
The translation
Ducafecat. Tech/categories /…
The open source project
Ducafecat. Tech/categories /…
Dart programming language basics
Space.bilibili.com/404904528/c…
Start Flutter with zero basics
Space.bilibili.com/404904528/c…
Flutter combat news client from scratch
Space.bilibili.com/404904528/c…
Flutter component development
Space.bilibili.com/404904528/c…
Flutter Bloc
Space.bilibili.com/404904528/c…
Flutter Getx4
Space.bilibili.com/404904528/c…
Docker Yapi
Space.bilibili.com/404904528/c…