Here is the Snippet to achieve toggling CupertinoSegmentedControl
programmatically.
where sliderkey
is given to CupertinoSegmentedControl
widget.
void toggle(int index) {
final x = (sliderKey.currentContext!.findRenderObject() as RenderBox).size.width;
(sliderKey.currentState as dynamic)?.onTapUp(TapUpDetails(
kind: PointerDeviceKind.touch,
localPosition: Offset(index * (x / (widget.children.length)), (widget.children.length + 1))));
}