Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CupertinoPicker textStyle flutter

I'm new to flutter and I need help.

I'm creating an app where the user can select data through a CupertinoPicker.

The picker works fine, but I would like to change its style.

Currently the style is like that, but I want it to be like that.

Unfortunately I can't understand how to do it, I read this but I can't do it, I would like to change the color and size of the selected element, the color of the elements not selected and the color of the lines.

But I do not know how I can do it.

Can anyone help me understand please?

The code is this :

Container(

          ˙child: _showCupertinoPicker(
           context,
           book[currentPage].orari.map((orario) {
           return Center(
                     child: Text(orario,
                     style: TextStyle(color: CupertinoColors.activeBlue

                         )));
           }).toList())),
.
.
.
.

_showCupertinoPicker(BuildContext context, List<Widget> orariWidget) {
  return CupertinoPicker(
    backgroundColor: Colors.white,
    onSelectedItemChanged: (value) {},
    itemExtent: 40.0,
    children: orariWidget,
  );
}
like image 248
Simone Avatar asked Dec 06 '22 09:12

Simone


2 Answers

Its possible to style CupertinoPicker and CupertinoDatePicker using theme like this:

return MaterialApp(
  theme: ThemeData(
    cupertinoOverrideTheme: CupertinoThemeData(
      textTheme: CupertinoTextThemeData(
        dateTimePickerTextStyle: TextStyle(color: Colors.blue, fontSize: 16),
        pickerTextStyle: TextStyle(color: Colors.blue, fontSize: 12),
      )
    )
  )
)
like image 198
kashlo Avatar answered Dec 07 '22 22:12

kashlo


Wrap the CupertinoPicker() with another widget known as CupertinoTheme() as

CupertinoTheme(
     data: CupertinoThemeData(
         textTheme: CupertinoTextThemeData(
             pickerTextStyle: TextStyle(//Your normal TextStyling)
         ),
     ),
     child:CupertinoPicker(//Your Cupertino Picker)
)
like image 40
Subhadeep Saha Avatar answered Dec 07 '22 23:12

Subhadeep Saha