如何在 flutter 的日期选择器中更改今天的日期主题

问题描述 投票:0回答:1

我正在尝试更改日期选择器的主题,但我无法更改当前日期的主题 这是日期选择器代码:

  final DateTime? picked = await showDatePicker(
      context: context,
      initialDate: null,
      firstDate: DateTime(1900, 8),
      lastDate: DateTime.now(),
      builder: (context, child) {
        return Theme(
          data: Theme.of(context).copyWith(
            colorScheme: ColorScheme.light(
              primary: Colors.white, // <-- SEE HERE
              onPrimary: primary, // <-- SEE HERE
              onSurface: Colors.black, // <-// - SEE HERE
            ),
            textButtonTheme: TextButtonThemeData(
              style: TextButton.styleFrom(foregroundColor: primary),
            ),
          ),
          child: child!,
        );
      },
    );

flutter dart
1个回答
0
投票

您更改了错误的参数。日期选择器采用

datePickerTheme
。以下是使用示例:

       return Theme(
         data: Theme.of(context).copyWith(
           datePickerTheme: DatePickerThemeData(
             backgroundColor: const Color(0xFFFFFFFF),
             shadowColor: const Color(0xFF795548),
             elevation: 10.0,
             dividerColor: const Color(0xFFFFC108),
             surfaceTintColor: const Color(0xFFE81E63),
             headerBackgroundColor: const Color(0xFF69F0AE),
             headerForegroundColor: const Color(0xFF9E9E9E),
             rangePickerBackgroundColor: const Color(0xFFB2FF59),
             rangePickerElevation: 10.0,
             rangePickerHeaderBackgroundColor: const Color(0xFFFFFFFF),
             rangePickerHeaderForegroundColor: const Color(0xFFFFFFFF),
             todayBackgroundColor: MaterialStateProperty.resolveWith((states) {
               if (states.contains(MaterialState.selected)) {
                 return const Color(0xFFFFFFFF);
               }
               return const Color(0xFF000000);
             }),
             dayBackgroundColor: MaterialStateProperty.resolveWith((states) {
               if (states.contains(MaterialState.selected)) {
                 return const Color(0xFF000000);
               }
               return const Color(0xFFFFFFFF);
             }),
             dayForegroundColor: MaterialStateProperty.resolveWith((states) {
               if (states.contains(MaterialState.selected)) {
                 return const Color(0xFFFFFFFF);
               }
               return const Color(0xFFFFFFFF);
             }),
             confirmButtonStyle: ButtonStyle(
             backgroundColor: MaterialStateProperty.resolveWith((states) {
               if (states.contains(MaterialState.selected)) {
                 return const Color(0xFFFFFFFF);
               }
               return const Color(0xFFFFFFFF);
      }),
    ),
  ),
)),
© www.soinside.com 2019 - 2024. All rights reserved.