Basic Syntax of CupertinoPicker Widget
CupertinoPicker(
itemExtent: 40.0, // Height of each item in the picker
onSelectedItemChanged: (int index) {
// Callback function when an item is selected
// Use 'index' to determine which item was selected
},
children: <Widget>[
// List of widgets representing each item in the picker
Center(
child: Text('Item 1'),
),
Center(
child: Text('Item 2'),
),
// Add more items as needed
],
)
Flutter – CupertinoPicker Widget
The CupertinoPicker widget in Flutter is part of the Cupertino-themed widgets that mimic the design and behavior of iOS widgets. It’s specifically designed to create a scrollable list of items, allowing the user to select one item from the list by scrolling or picking it directly. In this article, we are going to implement the CupertinoPicker widget. A sample video is given below to get an idea about what we are going to do in this article.