createOneCupertinoPicker<T> method
Widget
createOneCupertinoPicker<T>({
- required List<
T> values, - required ValueChanged<
int> onSelectedChanged, - FixedExtentScrollController? scrollController,
- String displayOfValue(
- T e,
- int index
- bool isSelectedValue(
- T e,
- int index
- T? selectedValue,
Implementation
Widget createOneCupertinoPicker<T>({
required List<T> values,
required ValueChanged<int> onSelectedChanged,
FixedExtentScrollController? scrollController,
// get display text
String Function(T e, int index)? displayOfValue,
// check if selected
bool Function(T e, int index)? isSelectedValue,
T? selectedValue,
}) {
return Expanded(
flex: 1,
child: Container(
height: themeData.pickerHeight,
decoration: const BoxDecoration(color: Colors.white),
child: CupertinoPicker.builder(
itemExtent: themeData.pickerItemHeight,
backgroundColor: Colors.white,
scrollController: scrollController,
onSelectedItemChanged: onSelectedChanged,
childCount: values.length,
itemBuilder: (context, index) {
dynamic value = values[index];
String text = displayOfValue?.call(value, index) ?? (value != null ? '$value' : '');
bool? isSelected = isSelectedValue?.call(value, index) ?? value == selectedValue;
return Container(
alignment: Alignment.center,
height: themeData.pickerItemHeight,
child: Text(
text,
style: isSelected
? const TextStyle(color: Color(0xFF006BE1), fontSize: 18)
: TextStyle(color: const Color(0xFF31456A).withOpacity(0.36), fontSize: 16),
),
);
},
selectionOverlay: Column(
children: [
Container(
height: 0.5,
color: const Color(0xFF31456A).withOpacity(0.16),
),
const Spacer(),
Container(
height: 0.5,
color: const Color(0xFF31456A).withOpacity(0.16),
),
],
),
),
),
);
}