showModalPopupTitlesPicker function
Future<int?>
showModalPopupTitlesPicker(
- BuildContext context,
- List<
String> titles, { - double? height,
Implementation
Future<int?> showModalPopupTitlesPicker(
BuildContext context,
List<String> titles, {
double? height,
}) {
return showCupertinoModalPopup(
context: context,
builder: (context) {
int index = 0;
return Container(
height: height ?? 260,
color: Colors.white,
child: Column(
children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
BaseButton(
onPressed: () {
Navigator.of(context).pop(null);
},
child: Text(
'取消',
),
),
BaseButton(
onPressed: () {
Navigator.of(context).pop(index);
},
child: Text(
'确认',
),
),
],
),
),
Container(
height: (height ?? 260) - 60,
child: CupertinoPicker(
backgroundColor: Colors.white,
itemExtent: 36, //item的高度
onSelectedItemChanged: (changed) {
index = changed;
},
children: titles.map((text) => Text(text)).toList(),
),
),
],
),
);
},
);
}