简体   繁体   English

如何在 Cupertino 小部件中将颜色更改为相反的主题?

[英]How to change color to opposite theme in cupertino widget?

I have two buttons on the same page that bring up a date picker CupertinoDatePicker.我在同一页面上有两个按钮可以调出日期选择器 CupertinoDatePicker。 One button just opens the picker, no additional customizations.一键打开选择器,无需额外自定义。 The second one opens a picker that has a predefined theme locally opposite to the one currently enabled for the app.第二个打开一个选择器,该选择器具有与当前为应用启用的主题相反的本地预定义主题。 How can I change the color of the elements of one of them using the theme setting?如何使用主题设置更改其中一个元素的颜色? My code:我的代码:

 CupertinoButton( onPressed: _showDialog, child: const Text( 'Select date', style: TextStyle( fontSize: 22.0, ), ), ), void _showDialog() { showCupertinoModalPopup<void>( context: context, builder: (BuildContext context) => Container( height: 216, padding: const EdgeInsets.only(top: 6.0), margin: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), color: CupertinoColors.systemBackground.resolveFrom(context), child: SafeArea( top: false, child: CupertinoDatePicker( initialDateTime: _date, mode: CupertinoDatePickerMode.date, use24hFormat: true, onDateTimeChanged: (DateTime newDate) { setState(() => _date = newDate); }, ), ), ), ); }

For setState in dialog modal , must wrap first widget in modal into statefullBuilder.对于对话框模式中的 setState,必须将模式中的第一个小部件包装到 statefullBuilder 中。 You cant setState normally in modal dialog.您不能在模态对话框中正常设置状态。

See example code:见示例代码:

showModalBottomSheet(
context: context,
builder: (context) {
  return StatefulBuilder(
      builder: (BuildContext context, StateSetter setState) {
    return Container(
      height: heightOfModalBottomSheet,
      child: RaisedButton(onPressed: () {
        setState(() {
          heightOfModalBottomSheet += 10;
        });
      }),
    );
  });});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM