【问题标题】:Custom CupertinoDatePicker Flutter自定义 CupertinoDatePicker 颤振
【发布时间】:2021-12-09 22:42:59
【问题描述】:

我需要像这样制作一个 CupertinoDatePicker:

但是除了背景,我什么都改变不了。

我找到了这样的答案https://stackoverflow.com/a/57830696/16864379

这是我得到的:

但是哪个参数负责将活动颜色变为粉红色? 什么参数负责去除半透明的白色背衬? 谢谢。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    CupertinoDatePicker 的文本和活动文本使用相同的TextStyle,因此不能只更改活动颜色,而是同时更改两者。

    return itemPositioningBuilder(
                context,
                Text(
                  localizations.datePickerHour(displayHour),
                  semanticsLabel: localizations.datePickerHourSemanticsLabel(displayHour),
                  style: _themeTextStyle(context, isValid: _isValidHour(selectedAmPm, index)),
                ),
              );
    
    TextStyle _themeTextStyle(BuildContext context, { bool isValid = true }) {
      final TextStyle style = CupertinoTheme.of(context).textTheme.dateTimePickerTextStyle;
      return isValid ? style : style.copyWith(color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context));
    }
    
    • 改变两种颜色
    CupertinoTheme(
                  data: CupertinoThemeData(
                    textTheme: CupertinoTextThemeData(
                      dateTimePickerTextStyle: TextStyle(color: Colors.pink),
                    ),
                  ),
                  child: CupertinoDatePicker(onDateTimeChanged: (_) {}),
                )
    

    【讨论】:

      猜你喜欢
      • 2020-03-16
      • 1970-01-01
      • 2022-07-27
      • 2020-10-13
      • 2020-08-09
      • 2021-09-16
      • 2019-11-07
      • 2019-07-06
      • 1970-01-01
      相关资源
      最近更新 更多