formBuilderRadioGroup function

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

Implementation

formBuilderRadioGroup(Item, map, pType,{show=false}) {
  printO("Contains  ${Item["key"]}  ${map.containsKey(Item["key"])}");

  GlobalKey<FormFieldState> _formRadiobuilder= GlobalKey<FormFieldState>();

    return StatefulBuilder(builder:(context, setState){

         WidgetsBinding.instance.addPostFrameCallback((_) {

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


        return Padding(
      padding: const EdgeInsets.only(top: 8, bottom: 8, right: 8, left: 8),
        child:  Column(
           crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            Flexible(
                    flex: 1,
                    fit: FlexFit.loose,
                    child: Text(Item["label"])),
                    const SizedBox(height: 5),
            FormBuilderRadioGroup<String>(
              enabled: !show,
            initialValue:
                map[Item["key"]] != null ? map[Item["key"]].toString() : null,
            name: Item['key'],
            key: _formRadiobuilder,
            activeColor: Colors.lightBlue,
            decoration: InputDecoration(
              labelText: Item['label'],
              labelStyle:  TextStyle(
                  fontFamily: 'Tajawal',
                  fontSize: 16,
                  //color: const Color(0xff42487e),
                  height: 1

              ),border: InputBorder.none

            ),
            onSaved: (value) {
              if(value!=null)
              map[Item["key"]] = value;
            },
            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;
              // }
            ]),
                ),
          ],
        ));
    ;});

}