【问题标题】:showDatePicker theme change not working after update?更新后 showDatePicker 主题更改不起作用?
【发布时间】:2020-08-04 18:35:23
【问题描述】:

我正在使用 builder 函数设置 showDatePicker 的主题:

showDatePicker(
  initialDate: initialDate,
  firstDate: initialDate,
  lastDate: maxDate,
  context: context,
  builder:
      (BuildContext context, Widget child) {
    return Theme(
        data: Theme.of(context).copyWith(
          primaryColor: Colors.orange,
          accentColor: Colors.orange,
          buttonTheme: ButtonThemeData(
            buttonColor: Colors.orange,
            splashColor: Colors.orange,
            colorScheme:
                ColorScheme.fromSwatch(
                    accentColor:
                        Colors.orange),
          ),
        ),
        child: child);
  },
);

这曾经适用于旧版本的颤振(v1.12.13+hotfix.8),但在当前版本(v1.17.5)上不再适用。

我也试过用自定义主题包装整个函数调用

Theme(
    data: ThemeData(primarySwatch: Colors.orange),
    child: MaterialButton(onTap: () {time = await ShowDatePicker (...)}

但这也不会改变日期选择器主题。

这是一个错误还是现在有其他方法可以更改主题?

为 showDatePicker 设置自定义主题的调用应该是什么?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    showDatePickerbuilder 中为ThemeData 设置colorSchemebuttonTheme

    showDatePicker(
            initialDate: initialDate,
            firstDate: initialDate,
            lastDate: maxDate,
            context: context,
            builder: (BuildContext context, Widget child) {
              return Theme(
                data: ThemeData.light().copyWith(
                  colorScheme:
                  ColorScheme.light(primary: Colors.redAccent),
                  buttonTheme: ButtonThemeData(
                      textTheme: ButtonTextTheme.primary),
                ),
                child: child,
              );
            });
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 2019-05-27
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      相关资源
      最近更新 更多