add readonly mode to toggle

This commit is contained in:
2025-06-09 15:01:38 +02:00
parent 7c223e088c
commit fba90d5925

View File

@@ -5,6 +5,7 @@ class MihToggle extends StatefulWidget {
final bool initialPostion;
final Color fillColor;
final Color secondaryFillColor;
final bool? readOnly;
final void Function(bool) onChange;
const MihToggle({
super.key,
@@ -12,6 +13,7 @@ class MihToggle extends StatefulWidget {
required this.initialPostion,
required this.fillColor,
required this.secondaryFillColor,
this.readOnly,
required this.onChange,
});
@@ -49,11 +51,20 @@ class _MihToggleState extends State<MihToggle> {
const SizedBox(width: 10),
Switch(
value: widget.initialPostion,
activeColor: widget.secondaryFillColor,
activeTrackColor: widget.fillColor,
inactiveThumbColor: widget.fillColor,
inactiveTrackColor: widget.secondaryFillColor,
onChanged: widget.onChange,
activeColor:
widget.readOnly == true ? Colors.grey : widget.secondaryFillColor,
activeTrackColor:
widget.readOnly == true ? Colors.grey.shade400 : widget.fillColor,
inactiveThumbColor:
widget.readOnly == true ? Colors.grey : widget.fillColor,
inactiveTrackColor: widget.readOnly == true
? Colors.grey.shade400
: widget.secondaryFillColor,
// activeColor: widget.secondaryFillColor,
// activeTrackColor: widget.fillColor,
// inactiveThumbColor: widget.fillColor,
// inactiveTrackColor: widget.secondaryFillColor,
onChanged: widget.readOnly != true ? widget.onChange : null,
),
],
);