本文介绍了使用滑块按钮创建分段控件小部件-Flutter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建与此类似的内容?:
How do I create something similar to this?:
演示:
我知道扑打有声
CupertinoSegmentedControl()
但这会创建类似于选项卡的内容,没有滑动像带有按钮的Switch之类的东西.
But this creates something similar to tabs, nothing that slides like something a Switch with a button inside.
推荐答案
我发现的最好的东西是CupertinoSlidingSegmentedControl()
:
Best thing I have found is the CupertinoSlidingSegmentedControl()
:
class _ViewState extends State<View> {
int segmentedControlGroupValue = 0;
final Map<int, Widget> myTabs = const <int, Widget>{
0: Text("Item 1"),
1: Text("Item 2")
};
@override
Widget build(BuildContext context) {
return Scaffold(
body: CupertinoSlidingSegmentedControl(
groupValue: segmentedControlGroupValue,
children: myTabs,
onValueChanged: (i) {
setState(() {
segmentedControlGroupValue = i;
});
}),
);
}
}
希望这会有所帮助.请参阅文档此处.
Hope this helps. See the docs here.
这篇关于使用滑块按钮创建分段控件小部件-Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!