我是颤动的新手,我需要帮助。
我正在创建一个应用程序,用户可以通过CupertinoPicker选择数据。
采摘器工作得很好,但我想改变它的风格。
不幸的是,我不知道怎么做,我读了这,但我做不到,我想改变所选元素的颜色和大小,没有选择的元素的颜色和线条的颜色。
但我不知道该怎么做。
有人能帮我理解一下吗?
代码是:
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,
);
}发布于 2019-12-18 22:35:01
可以使用这样的主题来设计CupertinoPicker和CupertinoDatePicker的样式:
return MaterialApp(
theme: ThemeData(
cupertinoOverrideTheme: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(color: Colors.blue, fontSize: 16),
pickerTextStyle: TextStyle(color: Colors.blue, fontSize: 12),
)
)
)
)发布于 2020-05-12 17:12:09
将CupertinoPicker()与另一个称为CupertinoTheme()的小部件包装为
CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
pickerTextStyle: TextStyle(//Your normal TextStyling)
),
),
child:CupertinoPicker(//Your Cupertino Picker)
)发布于 2019-09-16 13:22:15
我知道这个解决方案是冗长的,但它有效:
final cupertinoTheme = CupertinoTheme.of(context);
// Do your customising here:
final pickerTextStyle =
cupertinoTheme.textTheme.pickerTextStyle.copyWith(fontSize: 18.0, color: Colors.cyan);
final textTheme =
cupertinoTheme.textTheme.copyWith(pickerTextStyle: pickerTextStyle);
return CupertinoTheme(
data: cupertinoTheme.copyWith(textTheme: textTheme),
child: yourPickerGoesHere,
);CupertinoPicker从CupertinoTheme.of(context).textTheme.pickerTextStyle中获取文本样式。我们在这里所做的就是用我们的设置更新pickerTextStyle。
https://stackoverflow.com/questions/57269975
复制相似问题