toggle fix from inside mih windows
This commit is contained in:
@@ -25,12 +25,20 @@ class MihToggle extends StatefulWidget {
|
|||||||
class _MihToggleState extends State<MihToggle> {
|
class _MihToggleState extends State<MihToggle> {
|
||||||
late bool togglePosition;
|
late bool togglePosition;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant MihToggle oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.initialPostion != oldWidget.initialPostion) {
|
||||||
|
setState(() {
|
||||||
|
togglePosition = widget.initialPostion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
setState(() {
|
togglePosition = widget.initialPostion;
|
||||||
togglePosition = widget.initialPostion;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -51,7 +59,7 @@ class _MihToggleState extends State<MihToggle> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Switch(
|
Switch(
|
||||||
value: widget.initialPostion,
|
value: togglePosition,
|
||||||
trackOutlineColor: WidgetStateProperty.resolveWith<Color?>(
|
trackOutlineColor: WidgetStateProperty.resolveWith<Color?>(
|
||||||
(states) {
|
(states) {
|
||||||
if (widget.readOnly == true) {
|
if (widget.readOnly == true) {
|
||||||
@@ -81,7 +89,15 @@ class _MihToggleState extends State<MihToggle> {
|
|||||||
// activeTrackColor: widget.fillColor,
|
// activeTrackColor: widget.fillColor,
|
||||||
// inactiveThumbColor: widget.fillColor,
|
// inactiveThumbColor: widget.fillColor,
|
||||||
// inactiveTrackColor: widget.secondaryFillColor,
|
// 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,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user