Flutter: iOS CupertinoPicker Implementation Code

CupertinoPicker is an iOS feature that is used to pick and item from a list. It provides a function similar to the dropdown feature in Android.

Flutter Code for CupertinoPicker

const List<String> currenciesList = [
  'AUD',
  'BRL',
  'CAD',
  'CNY',
  'EUR',
  'GBP',
  'HKD',
  'IDR',
  'ILS',
  'INR',
  'JPY',
  'MXN',
  'NOK',
  'NZD',
  'PLN',
  'RON',
  'RUB',
  'SEK',
  'SGD',
  'USD',
  'ZAR'
];


  CupertinoPicker iOSPicker(){
    List<Text> pickerItems = [];

    for(String currency in currenciesList){
      pickerItems.add((Text(currency)));
    }

    return CupertinoPicker(
      backgroundColor: Colors.lightBlue,
      itemExtent: 32.0,
      onSelectedItemChanged: (selectedIndex){
        print(selectedIndex);
      },
      children: pickerItems,
    );
  }
          Container(
            height: 150.0,
            alignment: Alignment.center,
            padding: EdgeInsets.only(bottom: 30.0),
            color: Colors.lightBlue,
            child:  iOSPicker(),
          ),

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *