toggle fix from inside mih windows

This commit is contained in:
2025-07-04 10:21:03 +02:00
parent bc5850272c
commit df026dcfe7

View File

@@ -25,12 +25,20 @@ class MihToggle extends StatefulWidget {
class _MihToggleState extends State<MihToggle> {
late bool togglePosition;
@override
void didUpdateWidget(covariant MihToggle oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.initialPostion != oldWidget.initialPostion) {
setState(() {
togglePosition = widget.initialPostion;
});
}
}
@override
void initState() {
super.initState();
setState(() {
togglePosition = widget.initialPostion;
});
togglePosition = widget.initialPostion;
}
@override
@@ -51,7 +59,7 @@ class _MihToggleState extends State<MihToggle> {
),
const SizedBox(width: 10),
Switch(
value: widget.initialPostion,
value: togglePosition,
trackOutlineColor: WidgetStateProperty.resolveWith<Color?>(
(states) {
if (widget.readOnly == true) {
@@ -81,7 +89,15 @@ class _MihToggleState extends State<MihToggle> {
// activeTrackColor: widget.fillColor,
// inactiveThumbColor: widget.fillColor,
// inactiveTrackColor: widget.secondaryFillColor,
onChanged: widget.readOnly != true ? widget.onChange : null,
// onChanged: widget.readOnly != true ? widget.onChange : null,
onChanged: widget.readOnly != true
? (newValue) {
setState(() {
togglePosition = newValue; // Update internal state
});
widget.onChange(newValue); // Call the parent's onChange
}
: null,
),
],
);