forked from firka/flutter
Add cancelButtonStyle & confirmButtonStyle to the DatePickerThemeData (#132847)
fixes [Unable to adjust the color for "Cancel" and "Ok" button in datePicker dialog](https://github.com/flutter/flutter/issues/127739) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( useMaterial3: true, datePickerTheme: DatePickerThemeData( cancelButtonStyle: TextButton.styleFrom( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(16)), side: BorderSide(color: Colors.red), ), backgroundColor: Colors.white, foregroundColor: Colors.red, elevation: 3, shadowColor: Colors.red, ), confirmButtonStyle: TextButton.styleFrom( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(16)), ), backgroundColor: Colors.green[700], foregroundColor: Colors.white, elevation: 3, shadowColor: Colors.green[700], ), ), ), home: const Example(), ); } } class Example extends StatelessWidget { const Example({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: DatePickerDialog( initialDate: DateTime.now(), firstDate: DateTime(2020), lastDate: DateTime(2030), ), ), ); } } ``` </details> ### Before Not possible to customize action buttons from the `DatePickerThemeData`. ### After 
This commit is contained in:
@@ -56,6 +56,16 @@ class _${blockName}DefaultsM3 extends DatePickerThemeData {
|
||||
@override
|
||||
Color? get backgroundColor => ${componentColor("md.comp.date-picker.modal.container")};
|
||||
|
||||
@override
|
||||
ButtonStyle get cancelButtonStyle {
|
||||
return TextButton.styleFrom();
|
||||
}
|
||||
|
||||
@override
|
||||
ButtonStyle get confirmButtonStyle {
|
||||
return TextButton.styleFrom();
|
||||
}
|
||||
|
||||
@override
|
||||
Color? get shadowColor => ${colorOrTransparent("md.comp.date-picker.modal.container.shadow-color")};
|
||||
|
||||
@@ -231,8 +241,6 @@ class _${blockName}DefaultsM3 extends DatePickerThemeData {
|
||||
|
||||
@override
|
||||
TextStyle? get rangePickerHeaderHelpStyle => ${textStyle("md.comp.date-picker.modal.range-selection.month.subhead")};
|
||||
|
||||
|
||||
}
|
||||
''';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user