import 'package:flutter/material.dart';

class BooleanFormField extends StatefulWidget {
  final bool value;
  final String label;
  final void Function(bool) onChanged;
  final bool? enabled;
  final EdgeInsets? contentPadding;

  const BooleanFormField(
      {Key? key,
      required this.value,
      required this.label,
      required this.onChanged,
      this.enabled,
      this.contentPadding})
      : super(key: key);

  @override
  _BooleanFormFieldState createState() => _BooleanFormFieldState();
}

class _BooleanFormFieldState extends State<BooleanFormField> {
  @override
  Widget build(BuildContext context) {
    return FormField<bool>(builder: (state) {
      return ListTile(
        contentPadding: widget.contentPadding,
        onTap: () => widget.onChanged(!widget.value),
        trailing: Switch(
          value: widget.value,
          onChanged: widget.onChanged,
        ),
        title: Text(widget.label),
        enabled: widget.enabled ?? true,
      );
    });
  }
}