flutter CupertinoPicker控件
flutterCupertinoPick
·
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
List pickerChildren = ["1", "2", "3","4","5","6","7","8","9","10"];
var controllr=FixedExtentScrollController(initialItem:0);
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 200,
child:CupertinoPicker(
//子项高度,选中位置的高度
itemExtent: 30,
scrollController: controllr,
//直径比
diameterRatio: 1.1,
//轴偏移,默认是0.0。控制选中的子widget的左右偏移 正数 > 负数 < 0不偏移
offAxisFraction:0,
//放大效果 默认false false关闭 true开启
useMagnifier:true,
//放大倍数,需先开启放大效果,此参数才有作用。
magnification:1.3,
//压缩,这个控制的children之间的空隙,和diameterRatio的效果有相似之处。
squeeze:1.6,
backgroundColor:Colors.white,
//滚动选择的回调,每次滚动,都会触发此回调,会将选中的子widget的position返回。
onSelectedItemChanged: (int value) {
_counter=value;
print('The position is $value');
//controllr.selectedItem 相当于onSelectedItemChanged中position
//当前选择的第几个item
print(controllr.selectedItem);
},
children: pickerChildren.map((e){
return Text("${e}天",style:TextStyle(color:Colors.black));
}).toList(),
),
),
],
),
),
);
}
}
更多推荐
已为社区贡献2条内容
所有评论(0)