diff --git a/dev/tools/gen_defaults/lib/time_picker_template.dart b/dev/tools/gen_defaults/lib/time_picker_template.dart index b1aa65ecda..a10e5b35c5 100644 --- a/dev/tools/gen_defaults/lib/time_picker_template.dart +++ b/dev/tools/gen_defaults/lib/time_picker_template.dart @@ -132,7 +132,7 @@ class _${blockName}DefaultsM3 extends _TimePickerDefaults { @override Color get dialBackgroundColor { - return ${componentColor(dialComponent)}.withOpacity(_colors.brightness == Brightness.dark ? 0.12 : 0.08); + return ${componentColor(dialComponent)}; } @override diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index 1d2e9dc2a9..bde201785a 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -3434,7 +3434,7 @@ class _TimePickerDefaultsM3 extends _TimePickerDefaults { @override Color get dialBackgroundColor { - return _colors.surfaceVariant.withOpacity(_colors.brightness == Brightness.dark ? 0.12 : 0.08); + return _colors.surfaceVariant; } @override diff --git a/packages/flutter/lib/src/material/time_picker_theme.dart b/packages/flutter/lib/src/material/time_picker_theme.dart index e340cf9edf..cb18b26645 100644 --- a/packages/flutter/lib/src/material/time_picker_theme.dart +++ b/packages/flutter/lib/src/material/time_picker_theme.dart @@ -136,8 +136,14 @@ class TimePickerThemeData with Diagnosticable { /// The background color of the time picker dial when the entry mode is /// [TimePickerEntryMode.dial] or [TimePickerEntryMode.dialOnly]. /// - /// If this is null, the time picker defaults to the overall theme's - /// [ColorScheme.primary]. + /// If this is null and [ThemeData.useMaterial3] is true, the time picker + /// dial background color defaults [ColorScheme.surfaceVariant] color. + /// + /// If this is null and [ThemeData.useMaterial3] is false, the time picker + /// dial background color defaults to [ColorScheme.onSurface] color with + /// an opacity of 0.08 when the overall theme's brightness is [Brightness.light] + /// and [ColorScheme.onSurface] color with an opacity of 0.12 when the overall + /// theme's brightness is [Brightness.dark]. final Color? dialBackgroundColor; /// The color of the time picker dial's hand when the entry mode is diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index 1cb1c9a419..86a0f32d6b 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_picker_test.dart @@ -12,6 +12,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../rendering/mock_canvas.dart'; import '../widgets/semantics_tester.dart'; import 'feedback_tester.dart'; @@ -225,6 +226,70 @@ void main() { expect(selectedLabels.map((dynamic tp) => tp.inner as bool), inner0To23); }); + testWidgets('Material3 - Dial background uses correct default color', (WidgetTester tester) async { + ThemeData theme = ThemeData(useMaterial3: true); + Widget buildTimePicker(ThemeData themeData) { + return MaterialApp( + theme: themeData, + home: Material( + child: Center( + child: Builder( + builder: (BuildContext context) { + return ElevatedButton( + child: const Text('X'), + onPressed: () { + showTimePicker( + context: context, + initialTime: const TimeOfDay(hour: 7, minute: 0), + ); + }, + ); + }, + ), + ), + ), + ); + } + + await tester.pumpWidget(buildTimePicker(theme)); + + // Open the time picker dialog. + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + + // Test default dial background color. + RenderBox dial = tester.firstRenderObject(find.byType(CustomPaint)); + expect( + dial, + paints + ..circle(color: theme.colorScheme.surfaceVariant) // Dial background color. + ..circle(color: Color(theme.colorScheme.primary.value)), // Dial hand color. + ); + + await tester.tap(find.text(okString)); // dismiss the dialog + await tester.pumpAndSettle(); + + // Test dial background color when theme color scheme is changed. + theme = theme.copyWith( + colorScheme: theme.colorScheme.copyWith( + surfaceVariant: const Color(0xffff0000), + ), + ); + await tester.pumpWidget(buildTimePicker(theme)); + + // Open the time picker dialog. + await tester.tap(find.text('X')); + await tester.pumpAndSettle(); + + dial = tester.firstRenderObject(find.byType(CustomPaint)); + expect( + dial, + paints + ..circle(color: const Color(0xffff0000)) // Dial background color. + ..circle(color: Color(theme.colorScheme.primary.value)), // Dial hand color. + ); + }); + for (final MaterialType materialType in MaterialType.values) { group('Dial (${materialType.name})', () { testWidgets('tap-select an hour', (WidgetTester tester) async { diff --git a/packages/flutter/test/material/time_picker_theme_test.dart b/packages/flutter/test/material/time_picker_theme_test.dart index 2c7ba77af8..9f07d5e38f 100644 --- a/packages/flutter/test/material/time_picker_theme_test.dart +++ b/packages/flutter/test/material/time_picker_theme_test.dart @@ -242,7 +242,7 @@ void main() { expect( dial, paints - ..circle(color: defaultTheme.colorScheme.surfaceVariant.withOpacity(0.08)) // Dial background color. + ..circle(color: defaultTheme.colorScheme.surfaceVariant) // Dial background color. ..circle(color: Color(defaultTheme.colorScheme.primary.value)), // Dial hand color. );