Skip to content

Commit 18e7ba5

Browse files
committed
2 parents ae60ff7 + 4cecda7 commit 18e7ba5

32 files changed

+400
-209
lines changed

packages/flutter_form_builder/lib/src/fields/form_builder_checkbox.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
23
import 'package:flutter_form_builder/flutter_form_builder.dart';
34

45
/// Single Checkbox field
@@ -42,6 +43,8 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
4243
/// {@macro flutter.widgets.Focus.autofocus}
4344
final bool autofocus;
4445

46+
final bool shouldRequestFocus;
47+
4548
/// If true the checkbox's [value] can be true, false, or null.
4649
///
4750
/// Checkbox displays a dash when its value is null.
@@ -86,14 +89,15 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
8689
FocusNode? focusNode,
8790
required this.title,
8891
this.activeColor,
92+
this.autofocus = false,
8993
this.checkColor,
90-
this.subtitle,
91-
this.secondary,
92-
this.controlAffinity = ListTileControlAffinity.leading,
9394
this.contentPadding = EdgeInsets.zero,
94-
this.autofocus = false,
95-
this.tristate = false,
95+
this.controlAffinity = ListTileControlAffinity.leading,
96+
this.secondary,
9697
this.selected = false,
98+
this.shouldRequestFocus = false,
99+
this.subtitle,
100+
this.tristate = false,
97101
}) : super(
98102
key: key,
99103
initialValue: initialValue,
@@ -117,11 +121,13 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
117121
isThreeLine: false,
118122
title: title,
119123
subtitle: subtitle,
120-
value: tristate? state.value : (state.value ?? false),
124+
value: tristate ? state.value : (state.value ?? false),
121125
onChanged: state.enabled
122-
? (val) {
123-
state.requestFocus();
124-
state.didChange(val);
126+
? (value) {
127+
if (shouldRequestFocus) {
128+
state.requestFocus();
129+
}
130+
state.didChange(value);
125131
}
126132
: null,
127133
checkColor: checkColor,

packages/flutter_form_builder/lib/src/fields/form_builder_checkbox_group.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
23
import 'package:flutter_form_builder/flutter_form_builder.dart';
34

45
/// A list of Checkboxes for selecting multiple options

packages/flutter_form_builder/lib/src/fields/form_builder_choice_chips.dart

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import 'package:flutter/material.dart';
2+
23
import 'package:flutter_form_builder/flutter_form_builder.dart';
34

45
/// A list of `Chip`s that acts like radio buttons
56
class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
7+
final bool shouldRequestFocus;
8+
69
/// The list of items the user can select.
710
final List<FormBuilderFieldOption<T>> options;
811

@@ -240,41 +243,41 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
240243

241244
/// Creates a list of `Chip`s that acts like radio buttons
242245
FormBuilderChoiceChip({
243-
Key? key,
244-
//From Super
245-
required String name,
246-
FormFieldValidator<T>? validator,
247-
T? initialValue,
248-
InputDecoration decoration = const InputDecoration(),
249-
ValueChanged<T?>? onChanged,
250-
ValueTransformer<T?>? valueTransformer,
251-
bool enabled = true,
252-
FormFieldSetter<T>? onSaved,
253246
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
254-
VoidCallback? onReset,
247+
bool enabled = true,
255248
FocusNode? focusNode,
249+
FormFieldSetter<T>? onSaved,
250+
FormFieldValidator<T>? validator,
251+
InputDecoration decoration = const InputDecoration(),
252+
Key? key,
253+
required String name, //From Super
256254
required this.options,
257-
this.selectedColor,
258-
this.disabledColor,
255+
T? initialValue,
256+
this.alignment = WrapAlignment.start,
259257
this.backgroundColor,
260-
this.shadowColor,
261-
this.selectedShadowColor,
262-
this.shape,
258+
this.crossAxisAlignment = WrapCrossAlignment.start,
259+
this.direction = Axis.horizontal,
260+
this.disabledColor,
263261
this.elevation,
264-
this.pressElevation,
262+
this.labelPadding,
263+
this.labelStyle,
265264
this.materialTapTargetSize,
266-
this.direction = Axis.horizontal,
267-
this.alignment = WrapAlignment.start,
268-
this.crossAxisAlignment = WrapCrossAlignment.start,
265+
this.padding,
266+
this.pressElevation,
269267
this.runAlignment = WrapAlignment.start,
270268
this.runSpacing = 0.0,
269+
this.selectedColor,
270+
this.selectedShadowColor,
271+
this.shadowColor,
272+
this.shape,
273+
this.shouldRequestFocus = false,
271274
this.spacing = 0.0,
272275
this.textDirection,
273276
this.verticalDirection = VerticalDirection.down,
274-
this.labelPadding,
275-
this.labelStyle,
276-
this.padding,
277277
this.visualDensity,
278+
ValueChanged<T?>? onChanged,
279+
ValueTransformer<T?>? valueTransformer,
280+
VoidCallback? onReset,
278281
}) : super(
279282
key: key,
280283
initialValue: initialValue,
@@ -310,7 +313,9 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
310313
onSelected: state.enabled
311314
? (selected) {
312315
final choice = selected ? option.value : null;
313-
state.requestFocus();
316+
if (shouldRequestFocus) {
317+
state.requestFocus();
318+
}
314319
state.didChange(choice);
315320
}
316321
: null,
@@ -319,7 +324,6 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
319324
backgroundColor: backgroundColor,
320325
shadowColor: shadowColor,
321326
selectedShadowColor: selectedShadowColor,
322-
// shape: shape,
323327
elevation: elevation,
324328
pressElevation: pressElevation,
325329
materialTapTargetSize: materialTapTargetSize,

packages/flutter_form_builder/lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import 'dart:core';
22

33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
5-
import 'package:flutter_form_builder/flutter_form_builder.dart';
65
import 'package:intl/intl.dart' as intl;
76

7+
import 'package:flutter_form_builder/flutter_form_builder.dart';
8+
89
/// Field for selecting a range of dates
910
class FormBuilderDateRangePicker extends FormBuilderField<DateTimeRange> {
1011
//TODO: Add documentation

packages/flutter_form_builder/lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import 'dart:async';
21
import 'dart:ui' as ui;
32

43
import 'package:flutter/material.dart';
54
import 'package:flutter/services.dart';
6-
import 'package:flutter_form_builder/flutter_form_builder.dart';
5+
76
import 'package:intl/intl.dart';
87

8+
import 'package:flutter_form_builder/flutter_form_builder.dart';
9+
910
enum InputType { date, time, both }
1011

1112
// enum PickerType { material, cupertino }

packages/flutter_form_builder/lib/src/fields/form_builder_dropdown.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:collection/collection.dart' show IterableExtension;
22
import 'package:flutter/material.dart';
3+
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
45

56
/// Field for Dropdown button
@@ -191,6 +192,8 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
191192
/// and bottom of the menu by at one menu item's height.
192193
final double? menuMaxHeight;
193194

195+
final bool shouldRequestFocus;
196+
194197
/// Creates field for Dropdown button
195198
FormBuilderDropdown({
196199
Key? key,
@@ -221,6 +224,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
221224
this.clearIcon = const Icon(Icons.close),
222225
this.onTap,
223226
this.autofocus = false,
227+
this.shouldRequestFocus = false,
224228
this.dropdownColor,
225229
this.focusColor,
226230
this.itemHeight = kMinInteractiveDimension,
@@ -245,7 +249,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
245249
// TextFormField
246250

247251
void changeValue(T? value) {
248-
state.requestFocus();
252+
if (shouldRequestFocus) {
253+
state.requestFocus();
254+
}
249255
state.didChange(value);
250256
}
251257

@@ -269,8 +275,8 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
269275
isDense: isDense,
270276
disabledHint: field.value != null
271277
? (items
272-
.firstWhereOrNull(
273-
(val) => val.value == field.value)
278+
.firstWhereOrNull((dropDownItem) =>
279+
dropDownItem.value == field.value)
274280
?.child ??
275281
Text(field.value.toString()))
276282
: disabledHint,

0 commit comments

Comments
 (0)