How to customize the switch button in a flutter

Sumit Tifane picture Sumit Tifane · Oct 19, 2019 · Viewed 42.4k times · Source

In my app, I want the switch is used to toggle a setting between on/off which is true/false respectively. When I went to build it, it turned out that flutter provides a default switch but it is not what I want, I want to customize it accordingly to my UI

This is the flutter switch button: -

enter image description here

Here is what I want: -

enter image description here

How can I make it possible for my UI?

Answer

makri aymen abderraouf picture makri aymen abderraouf · Mar 12, 2020

set

bool _switchValue=true;

in your screen.dart

 CupertinoSwitch(
              value: _switchValue,
              onChanged: (value) {
                setState(() {
                  _switchValue = value;
                });
              },
            ),