fixed keyboard closing ontap field

This commit is contained in:
Jorian van der Kolk 2022-10-25 09:17:08 +02:00
parent 7c30113d9f
commit e6b1605b89
2 changed files with 19 additions and 24 deletions

View file

@ -23,22 +23,19 @@ class ItemBuilder {
inputDecoration = inputDecoration =
options.inputDecorationField?[key] ?? options.inputDecoration; options.inputDecorationField?[key] ?? options.inputDecoration;
return Form( return TextFormField(
key: formKey, key: Key(key),
child: TextFormField( controller: controller,
key: Key(key), decoration: inputDecoration,
controller: controller, readOnly: options.readOnly,
decoration: inputDecoration, onFieldSubmitted: (value) {
readOnly: options.readOnly, if (formKey.currentState!.validate()) {
onFieldSubmitted: (value) { updateItem(value);
if (formKey.currentState!.validate()) { }
updateItem(value); },
} validator: (value) {
}, return options.validators?[key]?.call(value);
validator: (value) { },
return options.validators?[key]?.call(value);
},
),
); );
} }
return widget; return widget;

View file

@ -46,9 +46,7 @@ class ProfileWrapper extends StatefulWidget {
class _ProfileWrapperState extends State<ProfileWrapper> { class _ProfileWrapperState extends State<ProfileWrapper> {
List<Widget> defaultItems = []; List<Widget> defaultItems = [];
GlobalKey<FormState> firstNameKey = GlobalKey<FormState>(); GlobalKey<FormState> formKey = GlobalKey<FormState>();
GlobalKey<FormState> lastNameKey = GlobalKey<FormState>();
@override @override
void initState() { void initState() {
@ -61,7 +59,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
defaultItems.add( defaultItems.add(
builder.build( builder.build(
'first_name', 'first_name',
firstNameKey, formKey,
widget.user.firstName, widget.user.firstName,
null, null,
(v) { (v) {
@ -79,7 +77,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
defaultItems.add( defaultItems.add(
builder.build( builder.build(
'last_name', 'last_name',
lastNameKey, formKey,
widget.user.lastName, widget.user.lastName,
null, null,
(v) { (v) {
@ -98,7 +96,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
defaultItems.add( defaultItems.add(
widget.itemBuilder!.build( widget.itemBuilder!.build(
'first_name', 'first_name',
firstNameKey, formKey,
widget.user.firstName, widget.user.firstName,
null, null,
(v) { (v) {
@ -116,7 +114,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
defaultItems.add( defaultItems.add(
widget.itemBuilder!.build( widget.itemBuilder!.build(
'last_name', 'last_name',
lastNameKey, formKey,
widget.user.lastName, widget.user.lastName,
null, null,
(v) { (v) {
@ -197,7 +195,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
), ),
], ],
// all the items that have priority above the default items // all the items that have priority above the default items
child, Form(key: formKey, child: child),
if (widget.bottomActionText != null) ...[ if (widget.bottomActionText != null) ...[
SizedBox( SizedBox(
height: widget.style.betweenDefaultItemPadding, height: widget.style.betweenDefaultItemPadding,