79307541

Date: 2024-12-25 12:22:45
Score: 1
Natty:
Report link

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))));
}
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Abrar Malekji