如何更改日期选择器按钮的颜色?

时间:2020-06-04 08:27:22

标签: flutter dart

请提出如何在颤动中更改日期选择器的按钮颜色?

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以通过更改主题中的primarySwatch来更改颜色:

MaterialApp(
  theme: ThemeData(primarySwatch: Colors.pink),
  ...
)

答案 1 :(得分:0)

<块引用>

如果您在 2021 年换色时仍然面临空安全问题..那么 这是简单的解决方案

       Future<void> _selectDate(BuildContext context) async {
DateTime? picked = await showDatePicker(
      context: context,
    builder: (BuildContext context, Widget ?child) {
      return Theme(
        data: ThemeData(
          primarySwatch: Colors.grey,
          splashColor: Colors.black,
          textTheme: TextTheme(
            subtitle1: TextStyle(color: Colors.black),
            button: TextStyle(color: Colors.black),
          ),
          accentColor: Colors.black,
          colorScheme: ColorScheme.light(
              primary: Color(0xffffbc00),
              primaryVariant: Colors.black,
              secondaryVariant: Colors.black,
              onSecondary: Colors.black,
              onPrimary: Colors.white,
              surface: Colors.black,
              onSurface: Colors.black,
              secondary: Colors.black),
              dialogBackgroundColor: Colors.white,
        ),
        child: child ??Text(""),
      );
    }
    initialDate: selectedDate,
    firstDate: DateTime(1960, 8),
    lastDate: DateTime.now());
if (picked != null && picked != selectedDate)
  setState(() {
    selectedDate = picked;


    String da = picked.day.toString() +
        "-" +
        picked.month.toString() +
        "-" +
        picked.year.toString();
    dateOfBirth.text = da;
  });
相关问题