'Slider switch in Flutter

I want to make a sliding switch like this

enter image description here

and I also made it through CupertinoSlidingSegmentedControl() but it is not meeting my requirements. I would like a similar slider switch.

I've made like this.

enter image description here

Neumorphic(
              style: NeumorphicStyle(
                  depth: NeumorphicTheme.embossDepth(context),
                  boxShape: const NeumorphicBoxShape.stadium(),
                  intensity: 1),
              child: ToggleSwitch(
                minWidth: 120.0,
                minHeight: 70,
                cornerRadius: 50.0,
                activeBgColors: const [
                  [Colors.cyan],
                  [Colors.cyan]
                ],
                inactiveBgColor: Colors.grey[200],
                inactiveFgColor: Colors.grey,
                totalSwitches: 2,
                labels: ['Agency', 'Freelancer'],
                radiusStyle: true,
                onToggle: (index) {},
              ),
            
            ),


Solution 1:[1]

you can use this package toggle_switch: ^1.4.0 and create it like this

SizedBox(
      height: 40,
      child: ToggleSwitch(
        minWidth: 90.0,
        cornerRadius: 20.0,
        activeBgColors: [const [Colors.cyan],const [Colors.cyan]],
        activeFgColor: Colors.white,
        inactiveBgColor: Colors.grey,
        inactiveFgColor: Colors.white,
        initialLabelIndex: 1,
        totalSwitches: 2,
        labels: ['Agency', 'Freelancer'],
        radiusStyle: true,
        onToggle: (index) {
          print('switched to: $index');
        },
      ),
    ),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman