どうも、ちょげ(@chogetarou)です。
DatePickerで表示するカレンダーの背景色を変えるには、どうしたらいいのでしょうか?
方法

final newDate = await showDatePicker(
context: context,
initialDate: initialDate,
firstDate: DateTime(DateTime.now().year - 3),
lastDate: DateTime(DateTime.now().year + 3),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(
primary: Colors.yellow, // ヘッダー背景色
onPrimary: Colors.black,
surface: Colors.red, //
onSurface: Colors.red, // カレンダーのテキストカラー
),
dialogBackgroundColor: Colors.blue,//カレンダーの背景色
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.red, // ボタンのテキスト
),
),
),
child: child!,
);
},
);
showDatePicker関数の引数「builder」にThemeを返すことで、DatePickerの色を変えることが出来ます。
Themeの引数「dialogBackgroundColor」を使うことで、カレンダーの背景色を変えることが出来ます。
コメント