Skip to content

Commit

Permalink
use FocusNode for unfocusing
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd committed Feb 12, 2024
1 parent 0162b3b commit 561a0d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
9 changes: 8 additions & 1 deletion lib/features/payments/search_payment_methods_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SearchPaymentMethodsPage extends HookWidget {
@override
Widget build(BuildContext context) {
final searchText = useState('');
final focusNode = useFocusNode();

return Scaffold(
appBar: AppBar(scrolledUnderElevation: 0),
Expand All @@ -33,9 +34,15 @@ class SearchPaymentMethodsPage extends HookWidget {
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
focusNode: focusNode,
onTapOutside: (_) => focusNode.unfocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
labelText: Loc.of(context).search,
prefixIcon: const Icon(Icons.search),
prefixIcon: const Padding(
padding: EdgeInsets.only(top: Grid.xs),
child: Icon(Icons.search)),
),
onChanged: (value) => searchText.value = value,
),
Expand Down
40 changes: 22 additions & 18 deletions lib/shared/json_schema_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@ class JsonSchemaForm extends HookWidget {
@override
Widget build(BuildContext context) {
final jsonSchema = json.decode(schema);

List<Widget> formFields = [];
jsonSchema['properties']?.forEach((key, value) {
formFields.add(TextFormField(
decoration: InputDecoration(
labelText: value['title'] ?? key,
labelStyle: TextStyle(
color: Theme.of(context).colorScheme.outlineVariant,
jsonSchema['properties']?.forEach(
(key, value) {
final focusNode = useFocusNode();

formFields.add(
TextFormField(
focusNode: focusNode,
onTapOutside: (_) => focusNode.unfocus(),
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
labelText: value['title'] ?? key,
),
textInputAction: TextInputAction.next,
validator: (value) => _validateField(key, value, jsonSchema),
onSaved: (value) => formData[key] = value ?? '',
),
border: InputBorder.none,
),
validator: (value) => _validateField(key, value, jsonSchema),
onSaved: (value) => formData[key] = value ?? '',
));
});
);
},
);

return Form(
key: _formKey,
Expand All @@ -41,12 +49,8 @@ class JsonSchemaForm extends HookWidget {
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: Grid.side,
),
child: Column(
children: formFields,
),
padding: const EdgeInsets.symmetric(horizontal: Grid.side),
child: Column(children: formFields),
),
),
),
Expand Down

0 comments on commit 561a0d5

Please sign in to comment.