Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/material_ui/lib/src/calendar_date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1523,10 +1523,11 @@ class _YearPickerState extends State<YearPicker> {

BorderSide? borderSide;
if (isCurrentYear) {
borderSide = datePickerTheme.todayBorder ?? defaults.todayBorder;
if (borderSide != null) {
borderSide = borderSide.copyWith(color: textColor);
}
final bool hasCustomBorderColor =
datePickerTheme.todayBorder != null && datePickerTheme.todayBorder!.color.opacity != 0.0;
borderSide = hasCustomBorderColor
? datePickerTheme.todayBorder
: (datePickerTheme.todayBorder ?? defaults.todayBorder)?.copyWith(color: textColor);
}
final decoration = ShapeDecoration(
color: background,
Expand Down
4 changes: 2 additions & 2 deletions packages/material_ui/lib/src/date_picker_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ class DatePickerThemeData with Diagnosticable {
final WidgetStateProperty<Color?>? todayBackgroundColor;

/// Overrides the border used to paint the
/// [DatePickerDialog.currentDate] label in the grid of the date
/// picker.
/// [DatePickerDialog.currentDate] label in both the day grid and the year
/// selector of the date picker.
///
/// If the border side's [BorderSide.color] is transparent (has 0 opacity),
/// [todayForegroundColor] is used instead. Otherwise, the border's color
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog: |
- Fixes `DatePickerThemeData.todayBorder` color being overridden by `todayForegroundColor` in the year selector.
version: patch
80 changes: 80 additions & 0 deletions packages/material_ui/test/calendar_date_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ void main() {
DateTime? currentDate,
ValueChanged<DateTime>? onChanged,
TextDirection textDirection = TextDirection.ltr,
ThemeData? theme,
}) {
return MaterialApp(
theme: theme,
home: Material(
child: Directionality(
textDirection: textDirection,
Expand Down Expand Up @@ -2102,6 +2104,84 @@ void main() {
});
});

ShapeDecoration? findYearDecoration(WidgetTester tester, String year) {
final Container container = tester.widget<Container>(
find.ancestor(of: find.text(year), matching: find.byType(Container)).first,
);

return container.decoration as ShapeDecoration?;
}

// Regression test for https://github.com/flutter/flutter/issues/189298
testWidgets('Non-null todayBorder color should be respected over todayBackgroundColor', (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test description mentions todayBackgroundColor, but the test actually verifies that todayBorder is respected over todayForegroundColor. We should update the description to match the actual behavior being tested.

Suggested change
testWidgets('Non-null todayBorder color should be respected over todayBackgroundColor', (
testWidgets('Non-null todayBorder color should be respected over todayForegroundColor', (

WidgetTester tester,
) async {
const Color customBorderColor = Colors.red;
await tester.pumpWidget(
yearPicker(
theme: ThemeData(
datePickerTheme: DatePickerThemeData(
todayBorder: const BorderSide(color: customBorderColor),
todayForegroundColor: WidgetStateProperty.all(Colors.blue),
),
),
),
);

// The current year should be painted with custom border color.
final ShapeDecoration? decoration = findYearDecoration(tester, '2016');
final shape = decoration!.shape as OutlinedBorder;
expect(shape.side.color, customBorderColor);
});

// Regression test for https://github.com/flutter/flutter/issues/189298.
testWidgets('Non-null todayBorder color is used even when disabled', (WidgetTester tester) async {
const Color customBorderColor = Colors.red;
await tester.pumpWidget(
yearPicker(
firstDate: DateTime(2018, DateTime.june, 9),
lastDate: DateTime(2030, DateTime.december, 15),
selectedDate: DateTime(2020),
currentDate: DateTime(2016), // Not between first and last date.
theme: ThemeData(
datePickerTheme: DatePickerThemeData(
todayBorder: const BorderSide(color: customBorderColor),
todayForegroundColor: WidgetStateProperty.all(Colors.blue),
),
),
),
);

// The current year should be painted with the custom border color,
// not with foreground color opacity applied, even if it's disabled.
final ShapeDecoration? decoration = findYearDecoration(tester, '2016');
final shape = decoration!.shape as OutlinedBorder;
expect(shape.side.color, customBorderColor);
});

// Regression test for https://github.com/flutter/flutter/issues/189298.
testWidgets('Transparent todayBorder should fall back to foreground color', (
WidgetTester tester,
) async {
const Color customForegroundColor = Colors.green;
await tester.pumpWidget(
yearPicker(
theme: ThemeData(
datePickerTheme: DatePickerThemeData(
todayBorder: const BorderSide(color: Color(0x00000000)),
todayForegroundColor: WidgetStateProperty.all(customForegroundColor),
),
),
),
);

// The current year should use the foreground color since
// todayBorder color is transparent.
final ShapeDecoration? decoration = findYearDecoration(tester, '2016');
final shape = decoration!.shape as OutlinedBorder;
expect(shape.side.color, customForegroundColor);
});

group('Calendar Delegate', () {
testWidgets('Defaults to Gregorian calendar system', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down