どうも、ちょげ(@chogetarou)です。
DatePickerにThemeを設定するには、どうしたらいいのでしょうか?
方法

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,
onSurface: Colors.red, // カレンダーのテキストカラー
), //カレンダーの背景色
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.red, // ボタンのテキスト
),
),
),
child: child!,
);
},
);
Themeを設定するには、引数「builder」を使います。
引数「builder」に「Theme」を返します。
引数「child」に、builderのchildを指定すれば、DatePickerにThemeを設定することが出来ます。
コメント