Ver Fonte

toggle ToggleSwitch before what in turn changes internally is changed

ashilkn há 2 anos atrás
pai
commit
a75bee5267
1 ficheiros alterados com 14 adições e 2 exclusões
  1. 14 2
      lib/ui/components/toggle_switch_widget.dart

+ 14 - 2
lib/ui/components/toggle_switch_widget.dart

@@ -18,6 +18,13 @@ class ToggleSwitchWidget extends StatefulWidget {
 }
 
 class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
+  late bool toggleValue;
+  @override
+  void initState() {
+    toggleValue = widget.value.call();
+    super.initState();
+  }
+
   @override
   Widget build(BuildContext context) {
     final enteColorScheme = Theme.of(context).colorScheme.enteTheme.colorScheme;
@@ -31,10 +38,15 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
             activeColor: enteColorScheme.primary400,
             inactiveTrackColor: enteColorScheme.fillMuted,
             materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
-            value: widget.value.call(),
+            value: toggleValue,
             onChanged: (value) async {
+              setState(() {
+                toggleValue = value;
+              });
               await widget.onChanged.call();
-              setState(() {});
+              setState(() {
+                toggleValue = widget.value.call();
+              });
             },
           ),
         ),