Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic changing readonly state on fields not working #83

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class _FormBuilderCheckboxState extends State<FormBuilderCheckbox> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand Down Expand Up @@ -74,6 +73,7 @@ class _FormBuilderCheckboxState extends State<FormBuilderCheckbox> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_checkbox_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand Down Expand Up @@ -80,6 +79,7 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_chips_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class _FormBuilderChipsInputState extends State<FormBuilderChipsInput> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -62,6 +61,7 @@ class _FormBuilderChipsInputState extends State<FormBuilderChipsInput> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return SizedBox(
// height: 200.0,
child: FormField(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_date_time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -183,6 +182,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return DateTimePickerFormField(
key: _fieldKey,
inputType: widget.inputType,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -65,6 +64,7 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/fields/form_builder_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand Down Expand Up @@ -75,9 +74,10 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly && !_readonly,
enabled: !_readonly,
initialValue: widget.initialValue,
validator: (val) {
for (int i = 0; i < widget.validators.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_rate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class _FormBuilderRateState extends State<FormBuilderRate> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -54,6 +53,7 @@ class _FormBuilderRateState extends State<FormBuilderRate> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_segmented_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class _FormBuilderSegmentedControlState
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -52,6 +51,7 @@ class _FormBuilderSegmentedControlState

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
initialValue: widget.initialValue,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_signature_pad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class _FormBuilderSignaturePadState extends State<FormBuilderSignaturePad> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
_points = widget.points;
super.initState();
}
Expand All @@ -70,6 +69,7 @@ class _FormBuilderSignaturePadState extends State<FormBuilderSignaturePad> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField<Uint8List>(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class _FormBuilderSliderState extends State<FormBuilderSlider> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -65,6 +64,7 @@ class _FormBuilderSliderState extends State<FormBuilderSlider> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_stepper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class _FormBuilderStepperState extends State<FormBuilderStepper> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -56,6 +55,7 @@ class _FormBuilderStepperState extends State<FormBuilderStepper> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
enabled: !_readonly,
key: _fieldKey,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class _FormBuilderSwitchState extends State<FormBuilderSwitch> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
super.initState();
}

Expand All @@ -49,6 +48,7 @@ class _FormBuilderSwitchState extends State<FormBuilderSwitch> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return FormField(
key: _fieldKey,
enabled: !_readonly,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class FormBuilderTextFieldState extends State<FormBuilderTextField> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
if (widget.controller != null)
_textEditingController = widget.controller;
else
Expand All @@ -107,6 +106,7 @@ class FormBuilderTextFieldState extends State<FormBuilderTextField> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return TextFormField(
key: _fieldKey,
validator: (val) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fields/form_builder_typeahead.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class _FormBuilderTypeAheadState extends State<FormBuilderTypeAhead> {
void initState() {
_formState = FormBuilder.of(context);
_formState?.registerFieldKey(widget.attribute, _fieldKey);
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
_typeAheadController = TextEditingController(text: widget.initialValue);
_typeAheadController.addListener(() {
if (widget.onChanged != null) widget.onChanged(_typeAheadController.text);
Expand All @@ -96,6 +95,7 @@ class _FormBuilderTypeAheadState extends State<FormBuilderTypeAhead> {

@override
Widget build(BuildContext context) {
_readonly = (_formState?.readonly == true) ? true : widget.readonly;
return TypeAheadFormField(
key: _fieldKey,
validator: (val) {
Expand Down