formBuilderCheckboxGroup function

dynamic formBuilderCheckboxGroup(
  1. dynamic Item,
  2. dynamic map,
  3. dynamic pType, {
  4. dynamic show = false,
})

Implementation

formBuilderCheckboxGroup(Item, map, pType,{show=false}) {
   //Map<String,dynamic> das;
   //das.values.toList()
  printO("Contains  ${Item["key"]}  ${map.containsKey(Item["key"])}  , ${Item['values'] }");
  GlobalKey<FormFieldState> _formCheckbuilder= GlobalKey<FormFieldState>();

     return
      StatefulBuilder(builder:(context, setState){

         WidgetsBinding.instance.addPostFrameCallback((_) {

              // setState(() {
              //   // Capture the height
              // });
              _formCheckbuilder.currentState?.didChange( map.containsKey(Item["key"]) ? map[Item["key"]] : null);
            });


        return Column(
       crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Flexible(
                  flex: 1,
                  fit: FlexFit.loose,
                  child: Text(Item["label"])),
                  const SizedBox(height: 5),
         FormBuilderCheckboxGroup<String>(
          enabled: !show,
          name: Item['key'],
           key: _formCheckbuilder,

           initialValue:
               map.containsKey(Item["key"]) ? map[Item["key"]] : null,
           onSaved: (value) {
            if(value!=null)
             map[Item["key"]] = value;
           },


           decoration: InputDecoration(
             labelText: Item['label'],
             labelStyle:  TextStyle(
                 fontFamily: 'Tajawal',
                 fontSize: 14,
                 //color: const Color(0xff42487e),
                 height: 1

             )
           ),
           activeColor: Colors.lightBlue,
           options: Item['values'].length > 0
               ? Item['values']
                   .map<FormBuilderFieldOption<String>>((e) =>
                       FormBuilderFieldOption(
                           value: e['value'].toString(),
                           child: Text('${e['label']}',style:  TextStyle(
                               fontFamily: 'Tajawal',
                               fontSize: 14,
                               //color: const Color(0xff42487e),
                               height: 1

                           ),)))
                   .toList()
               : [],
           validator: FormBuilderValidators.compose([
             if (Item['validate'] != null &&
                 Item['validate']['required'] != null &&
                 Item['validate']['required'])
                FormBuilderValidators.required(errorText: Item['validate']['customMessage']??'Field is Required'),

             // FormBuilderValidators.numeric(context, errorText: 'La edad debe ser numérica.'),
             // FormBuilderValidators.max(context, 70),
             //     (val){
             //   if(val < 0)
             //     return 'We cannot have a negative age';
             //   return null;
             // }
           ]),
         ),
       ],
     );
      });
}