Reputation: 349
I am building in Flutter a custom Segmented Control that has too many options, so it should be scrolled horizontally to see all the options. That is the reason why I put the CupertinoSlidingSegmentedControl inside a SingleChildScrollView with horizontal scrollDirection.
In the Android emulator works ok and scrolls, but on the ios emulator it doesn't scroll.
I don't know what am I doing wrong.
I share the code:
import 'package:flutter/cupertino.dart';
class CustomSegmentedControl extends StatefulWidget {
const CustomSegmentedControl({Key? key}) : super(key: key);
@override
State<CustomSegmentedControl> createState() => _CustomSegmentedControlState();
}
class _CustomSegmentedControlState extends State<CustomSegmentedControl> {
// Por defecto le damos el valor de "todos".
int? groupValue = 0;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: CupertinoSlidingSegmentedControl(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
children: const {
0: Text("Todos"),
1: Text("2005"),
2: Text("2006"),
3: Text("2007"),
4: Text("2008"),
5: Text("2009"),
6: Text("2010"),
7: Text("2011"),
8: Text("2012"),
9: Text("2013"),
},
groupValue: groupValue,
onValueChanged: (value) {
setState(() {
groupValue = value;
});
},
),
);
}
}
Upvotes: 0
Views: 782
Reputation: 769
It worked on android, but iOS not. The reason is flutter add drag event handler on this widget, so scroll event will not effect.
Solution: copyCupertinoSlidingSegmentedControl
's file and remove the drag event code (like below image)
Upvotes: 1