Skip to content

Commit 0d0e657

Browse files
docs: Add especifc use case
1 parent 54987d5 commit 0d0e657

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Also included are common ready-made form input fields for FormBuilder. This give
88
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/flutter-form-builder-ecosystem/flutter_form_builder/Base?logo=github&style=for-the-badge)](https://github.com/flutter-form-builder-ecosystem/flutter_form_builder/actions/workflows/base.yaml)
99
[![Codecov](https://img.shields.io/codecov/c/github/flutter-form-builder-ecosystem/flutter_form_builder?logo=codecov&style=for-the-badge)](https://codecov.io/gh/flutter-form-builder-ecosystem/flutter_form_builder/)
1010
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/flutter-form-builder-ecosystem/flutter_form_builder?logo=codefactor&style=for-the-badge)](https://www.codefactor.io/repository/github/flutter-form-builder-ecosystem/flutter_form_builder)
11+
[![Discord](https://img.shields.io/discord/985922433578053673?logo=discord&style=for-the-badge)](https://discord.com/invite/25KNPMJQf2)
1112
___
1213

1314
- [Features](#features)
@@ -266,6 +267,57 @@ FormBuilderRadioGroup(
266267
),
267268
```
268269

270+
#### Implement reset, clear or other button into FormBuilderField
271+
272+
If you can add some button to reset specific field, can use the `decoration` parameter like this:
273+
274+
```dart
275+
List<String> genderOptions = ['Male', 'Female', 'Other'];
276+
277+
FormBuilderDropdown<String>(
278+
name: 'gender',
279+
decoration: InputDecoration(
280+
labelText: 'Gender',
281+
initialValue: 'Male',
282+
suffix: IconButton(
283+
icon: const Icon(Icons.close),
284+
onPressed: () {
285+
_formKey.currentState!.fields['gender']
286+
?.reset();
287+
},
288+
),
289+
hintText: 'Select Gender',
290+
),
291+
items: genderOptions
292+
.map((gender) => DropdownMenuItem(
293+
alignment: AlignmentDirectional.center,
294+
value: gender,
295+
child: Text(gender),
296+
))
297+
.toList(),
298+
),
299+
```
300+
301+
Or if is allowed by the field, set a value like this:
302+
303+
```dart
304+
FormBuilderTextField(
305+
name: 'age',
306+
decoration: InputDecoration(
307+
labelText: 'Age',
308+
suffixIcon: IconButton(
309+
icon: const Icon(Icons.plus_one),
310+
onPressed: () {
311+
_formKey.currentState!.fields['age']
312+
?.didChange('14');
313+
},
314+
),
315+
),
316+
initialValue: '13',
317+
keyboardType: TextInputType.number,
318+
),
319+
```
320+
269321
## Support
270322

271323
### Contribute

0 commit comments

Comments
 (0)