Skip to content

Commit 1d042a4

Browse files
committed
Attempted tab-next support. Closes #54
1 parent 7017efd commit 1d042a4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/src/form_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class FormBuilderState extends State<FormBuilder> {
166166
Widget build(BuildContext context) {
167167
return Form(
168168
key: _formKey,
169-
child: widget.child,
169+
child: FocusTraversalGroup(child: widget.child),
170170
autovalidate: widget.autovalidate,
171171
onWillPop: widget.onWillPop,
172172
onChanged: () {

lib/src/form_builder_field.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/scheduler.dart';
3+
import 'package:flutter/services.dart';
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
45

56
class FormBuilderField<T> extends FormField<T> {
@@ -72,6 +73,8 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
7273

7374
FocusNode _node;
7475

76+
FocusAttachment _nodeAttachment;
77+
7578
bool _focused = false;
7679

7780
@override
@@ -87,7 +90,7 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
8790
: null);
8891
_node = widget.focusNode ?? FocusNode(debugLabel: '${widget.attribute}');
8992
_node.addListener(_handleFocusChange);
90-
// _nodeAttachment = _node.attach(context, onKey: _handleKeyPress);
93+
_nodeAttachment = _node.attach(context, onKey: _handleKeyPress);
9194
setValue(_initialValue);
9295
}
9396

@@ -99,6 +102,17 @@ class FormBuilderFieldState<T> extends FormFieldState<T> {
99102
}
100103
}
101104

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+
102116
@override
103117
void dispose() {
104118
_formBuilderState?.unregisterFieldKey(widget.attribute);

0 commit comments

Comments
 (0)