radioButtonFormEntry<T> method

Widget radioButtonFormEntry<T>({
  1. String title = 'Radio Selection',
  2. String subTitle = 'Choose one option',
  3. required List<T> options,
  4. required String getDisplayText(
    1. T
    ),
  5. required dynamic onChanged(
    1. T?
    ),
  6. T? defaultValue,
  7. String? validator(
    1. T?
    )?,
  8. bool isRequired = false,
})

Implementation

Widget radioButtonFormEntry<T>({
  String title = 'Radio Selection',
  String subTitle = 'Choose one option',
  required List<T> options,
  required String Function(T) getDisplayText,
  required Function(T?) onChanged,
  T? defaultValue,
  String? Function(T?)? validator,
  bool isRequired = false,
}) {
  if (options.isEmpty) {
    throw ArgumentError('Options list cannot be empty');
  }

  return formEntry(
    title: title,
    subTitle: subTitle,
    inputWidget: Column(
      children: options.map((T option) {
        return RadioListTile<T>(
          title: Text(
            getDisplayText(option),
            style: const TextStyle(
              color: Colors.black87,
              fontSize: 16,
              fontWeight: FontWeight.w400,
            ),
          ),
          value: option,
          groupValue: defaultValue,
          activeColor: Colors.blue,
          onChanged: isEdit
              ? (T? value) {
                  onChanged(value);
                  widget.formKey.currentState?.save();
                  widget.onModified?.call();
                }
              : null,
        );
      }).toList(),
    ),
  );
}