builder property

Widget Function(T value, void onChanged(T?)) builder
final

Builder to be called each time the InjectedFormField emits a notification.

It exposes the current value the the onChanged callback.

In most cases any input form widget have a value and onChanged properties. You must set these properties to the exposed value and onChanged.

This is an example of a CheckBox.

 final myCheckBox = RM.injectFormField<bool>(
   false,
   validators: [(value) => !value ? 'You must check me' : null],
 );

//In the widget tree inside OnFormBuilder widget.
OnFormFieldBuilder<bool>(
   listenTo: myCheckBox,
   builder: (value, onChanged) {
     return CheckboxListTile(
       value: value,
       onChanged: onChanged,
       title: Text('I accept the licence'),
     );
   },
 ),

To deal with multi choice checkboxes (or FilterChips), you have to be more explicit on what to do in onChange callback.

Example of multi choice checkboxds:

 static const languages = ['Dart', 'Java', 'C++'];
 final myLanguages = RM.injectFormField<List<String>>([]);

//In the widget tree inside OnFormBuilder widget.
OnFormFieldBuilder<List<String>>(
   listenTo: myLanguages,
   builder: (value, onChanged) {
     return Row(
       children: languages
           .map(
             (e) => Row(
               children: [
                 Checkbox(
                   value: value.contains(e),
                   onChanged: (val) {
                     if (val == true) {
                       myLanguages.value = [...value, e];
                     } else {
                       myLanguages.value =
                           value.where((el) => el != e).toList();
                     }
                   },
                 ),
                 Text('$e'),
               ],
             ),
           )
           .toList(),
     );
   },
 ),

Implementation

final Widget Function(T value, void Function(T?) onChanged) builder;