You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class MyCheckbox extends StatelessWidget {
final String attribute;
final List options;
final String title;
final bool mandatory;
final ValueChanged onChanged;
const MyCheckbox(
{Key key,
this.attribute,
this.options,
this.mandatory,
this.title,
this.onChanged})
: super(key: key);
I am getting the following exception with FormBuilderCheckboxList:
I/flutter ( 3712): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 3712): The following NoSuchMethodError was thrown building
I/flutter ( 3712): FormField-[LabeledGlobalKey<FormFieldState>#9b66a](dirty, state:
I/flutter ( 3712): FormFieldState#3cadd):
I/flutter ( 3712): The method 'contains' was called on null.
I/flutter ( 3712): Receiver: null
I/flutter ( 3712): Tried calling: contains(0)
I/flutter ( 3712):
I/flutter ( 3712): When the exception was thrown, this was the stack:
I/flutter ( 3712): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter ( 3712): #1 _FormBuilderCheckboxListState._checkbox
package:flutter_form_builder/…/fields/form_builder_checkbox_list.dart:55
I/flutter ( 3712): #2 _FormBuilderCheckboxListState._leading
package:flutter_form_builder/…/fields/form_builder_checkbox_list.dart:71
I/flutter ( 3712): #3 _FormBuilderCheckboxListState.build.
package:flutter_form_builder/…/fields/form_builder_checkbox_list.dart:108
I/flutter ( 3712): #4 FormFieldState.build (package:flutter/src/widgets/form.dart)
What's the way to work around?
Following is my code:
class
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
class MyCheckbox extends StatelessWidget {
final String attribute;
final List options;
final String title;
final bool mandatory;
final ValueChanged onChanged;
const MyCheckbox(
{Key key,
this.attribute,
this.options,
this.mandatory,
this.title,
this.onChanged})
: super(key: key);
String _labelText() {
return mandatory
? title.substring(0, 1).toUpperCase() + title.substring(1) + '*'
: title.substring(0, 1).toUpperCase() + title.substring(1);
}
@OverRide
Widget build(BuildContext context) {
return FormBuilderCheckboxList(
attribute: attribute,
options: options,
initialValue: null,
decoration: InputDecoration(
labelText: _labelText(),
labelStyle: TextStyle(
color: Color(0xFF4574EC),
),
border: InputBorder.none,
),
leadingInput: true,
validators: mandatory
? [
FormBuilderValidators.required(
errorText: 'Please select $title',
)
]
: [],
onChanged: onChanged,
);
}
}
calling it
MyCheckbox(
attribute: 'treatment',
mandatory: false,
title: 'Treatment received',
options: [
FormBuilderFieldOption(value: 0, label: 'IV Fluids'),
FormBuilderFieldOption(value: 1, label: 'Antibiotics'),
FormBuilderFieldOption(value: 2, label: 'ORS'),
],
onChanged: (dynamic val) {
print('treatmentreceived=$val');
setState(() {
_treatment = val;
});
},
),
The text was updated successfully, but these errors were encountered: