File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ class FormBuilderState extends State<FormBuilder> {
166
166
Widget build (BuildContext context) {
167
167
return Form (
168
168
key: _formKey,
169
- child: widget.child,
169
+ child: FocusTraversalGroup (child : widget.child) ,
170
170
autovalidate: widget.autovalidate,
171
171
onWillPop: widget.onWillPop,
172
172
onChanged: () {
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter/scheduler.dart' ;
3
+ import 'package:flutter/services.dart' ;
3
4
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4
5
5
6
class FormBuilderField <T > extends FormField <T > {
@@ -72,6 +73,8 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
72
73
73
74
FocusNode _node;
74
75
76
+ FocusAttachment _nodeAttachment;
77
+
75
78
bool _focused = false ;
76
79
77
80
@override
@@ -87,7 +90,7 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
87
90
: null );
88
91
_node = widget.focusNode ?? FocusNode (debugLabel: '${widget .attribute }' );
89
92
_node.addListener (_handleFocusChange);
90
- // _nodeAttachment = _node.attach(context, onKey: _handleKeyPress);
93
+ _nodeAttachment = _node.attach (context, onKey: _handleKeyPress);
91
94
setValue (_initialValue);
92
95
}
93
96
@@ -99,6 +102,17 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
99
102
}
100
103
}
101
104
105
+ bool _handleKeyPress (FocusNode node, RawKeyEvent event) {
106
+ if (event is RawKeyDownEvent ) {
107
+ print ('Focus node ${node .debugLabel } got key event: ${event .logicalKey }' );
108
+ if (event.logicalKey == LogicalKeyboardKey .tab) {
109
+ FocusScope .of (context).nextFocus ();
110
+ return true ;
111
+ }
112
+ }
113
+ return false ;
114
+ }
115
+
102
116
@override
103
117
void dispose () {
104
118
_formBuilderState? .unregisterFieldKey (widget.attribute);
You can’t perform that action at this time.
0 commit comments