42 lines
1.0 KiB
Dart
42 lines
1.0 KiB
Dart
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;
|
|
final Icon? icon;
|
|
|
|
const BooleanFormField(
|
|
{Key? key,
|
|
required this.value,
|
|
required this.label,
|
|
required this.onChanged,
|
|
this.enabled,
|
|
this.contentPadding,
|
|
this.icon})
|
|
: super(key: key);
|
|
|
|
@override
|
|
_BooleanFormFieldState createState() => _BooleanFormFieldState();
|
|
}
|
|
|
|
class _BooleanFormFieldState extends State<BooleanFormField> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FormField<bool>(builder: (state) {
|
|
return ListTile(
|
|
leading: widget.icon,
|
|
contentPadding: widget.contentPadding,
|
|
onTap: () => widget.onChanged(!widget.value),
|
|
trailing: Switch(
|
|
value: widget.value,
|
|
onChanged: widget.onChanged,
|
|
),
|
|
title: Text(widget.label),
|
|
enabled: widget.enabled ?? true,
|
|
);
|
|
});
|
|
}
|
|
} |