【问题标题】:Flutter: showDatePicker change colors颤振:showDatePicker 改变颜色
【发布时间】:2020-09-27 10:54:51
【问题描述】:

我正在尝试更改日期选择器的颜色,但其中仍有蓝色。我尝试了很多,但我找不到改变蓝色的代码(见下文)。

文本:输入日期、下划线和取消和确定按钮都应该是青色。

到目前为止,这是我的代码。感谢支持!

  TextEditingController _dateController = new TextEditingController();
  DateTime selectedDate = DateTime.now();
  var myFormat = DateFormat('d-MM-yyyy');
  Future<void> _selectDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: selectedDate,
        firstDate: DateTime(1930),
        lastDate: DateTime(2022),
        builder: (BuildContext context, Widget child) {
          return Theme(
            data: ThemeData.light().copyWith(
              colorScheme: ColorScheme.fromSwatch(
                primarySwatch: Colors.teal,
                primaryColorDark: Colors.teal,
                accentColor: Colors.teal,
              ),
            dialogBackgroundColor:Colors.white,
          ),
          child: child,
       );
    },
    );
    if (picked != null && picked != selectedDate)
      setState(() {
        selectedDate = picked;
      });
  }

【问题讨论】:

  • 没有办法做到这一点,我能看到的唯一解决方案是在您的项目中添加 Flutter Date Picker 类并对其进行修改。

标签: flutter colors


【解决方案1】:

试试这个

TextEditingController _dateController = new TextEditingController();
DateTime selectedDate = DateTime.now();
var myFormat = DateFormat('d-MM-yyyy');
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
    context: context,
    initialDate: selectedDate,
    firstDate: DateTime(1930),
    lastDate: DateTime(2022),
    builder: (BuildContext context, Widget child) {
      return Theme(
        data: ThemeData.light().copyWith(
          colorScheme: ColorScheme.fromSwatch(
            primarySwatch: Colors.teal,
            primaryColorDark: Colors.teal,
            accentColor: Colors.teal,
          ),
        dialogBackgroundColor:Colors.white,
      ),
      child: child,
   );
},
);
if (picked != null && picked != selectedDate)
  setState(() {
    selectedDate = picked;
  });
}

【讨论】:

    【解决方案2】:

    这可能是一个反复试验的事情。我希望每个小部件使用的主题属性更明显。

    例如,我必须为 DropDownButton 使用 ThemeData.canvasColor。 colorScheme 属性似乎都没有对该小部件产生影响,因此它可能是 ThemeData 中可以帮助您的东西(并且有很多属性)

    也许这些?看起来日期将是一个 TextField。

    textSelectionColor → 颜色 文本字段中文本选择的颜色,例如 TextField。 最终的 textSelectionHandleColor → 颜色 用于调整当前选择的文本部分的手柄颜色。 最终

    【讨论】:

      猜你喜欢
      • 2019-04-19
      • 2021-11-24
      • 1970-01-01
      • 2019-12-04
      • 2021-04-19
      • 2021-08-23
      • 2018-06-05
      • 2021-08-19
      • 1970-01-01
      相关资源
      最近更新 更多