|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:flutter/cupertino.dart';
|
| 6 | +import 'package:flutter/foundation.dart'; |
6 | 7 | import 'package:flutter/gestures.dart';
|
7 | 8 | import 'package:flutter/material.dart';
|
8 | 9 | import 'package:flutter/rendering.dart';
|
@@ -38,7 +39,7 @@ void main() {
|
38 | 39 | expect(log, equals(<dynamic>[false, '-', false]));
|
39 | 40 | });
|
40 | 41 |
|
41 |
| - testWidgetsWithLeakTracking('CheckboxListTile checkColor test', (WidgetTester tester) async { |
| 42 | + testWidgetsWithLeakTracking('Material2 - CheckboxListTile checkColor test', (WidgetTester tester) async { |
42 | 43 | const Color checkBoxBorderColor = Color(0xff2196f3);
|
43 | 44 | Color checkBoxCheckColor = const Color(0xffFFFFFF);
|
44 | 45 |
|
@@ -70,6 +71,38 @@ void main() {
|
70 | 71 | expect(getCheckboxListTileRenderer(), paints..path(color: checkBoxBorderColor)..path(color: checkBoxCheckColor));
|
71 | 72 | });
|
72 | 73 |
|
| 74 | + testWidgetsWithLeakTracking('Material3 - CheckboxListTile checkColor test', (WidgetTester tester) async { |
| 75 | + const Color checkBoxBorderColor = Color(0xff6750a4); |
| 76 | + Color checkBoxCheckColor = const Color(0xffFFFFFF); |
| 77 | + |
| 78 | + Widget buildFrame(Color? color) { |
| 79 | + return MaterialApp( |
| 80 | + theme: ThemeData(useMaterial3: true), |
| 81 | + home: Material( |
| 82 | + child: CheckboxListTile( |
| 83 | + value: true, |
| 84 | + checkColor: color, |
| 85 | + onChanged: (bool? value) {}, |
| 86 | + ), |
| 87 | + ), |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + RenderBox getCheckboxListTileRenderer() { |
| 92 | + return tester.renderObject<RenderBox>(find.byType(CheckboxListTile)); |
| 93 | + } |
| 94 | + |
| 95 | + await tester.pumpWidget(buildFrame(null)); |
| 96 | + await tester.pumpAndSettle(); |
| 97 | + expect(getCheckboxListTileRenderer(), paints..path(color: checkBoxBorderColor)..path(color: checkBoxCheckColor)); |
| 98 | + |
| 99 | + checkBoxCheckColor = const Color(0xFF000000); |
| 100 | + |
| 101 | + await tester.pumpWidget(buildFrame(checkBoxCheckColor)); |
| 102 | + await tester.pumpAndSettle(); |
| 103 | + expect(getCheckboxListTileRenderer(), paints..path(color: checkBoxBorderColor)..path(color: checkBoxCheckColor)); |
| 104 | + }); |
| 105 | + |
73 | 106 | testWidgetsWithLeakTracking('CheckboxListTile activeColor test', (WidgetTester tester) async {
|
74 | 107 | Widget buildFrame(Color? themeColor, Color? activeColor) {
|
75 | 108 | return wrap(
|
@@ -710,7 +743,7 @@ void main() {
|
710 | 743 | );
|
711 | 744 | });
|
712 | 745 |
|
713 |
| - testWidgets('CheckboxListTile respects overlayColor in active/pressed/hovered states', (WidgetTester tester) async { |
| 746 | + testWidgets('Material2 - CheckboxListTile respects overlayColor in active/pressed/hovered states', (WidgetTester tester) async { |
714 | 747 | tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
715 | 748 |
|
716 | 749 | const Color fillColor = Color(0xFF000000);
|
@@ -826,6 +859,129 @@ void main() {
|
826 | 859 | );
|
827 | 860 | });
|
828 | 861 |
|
| 862 | + testWidgets('Material3 - CheckboxListTile respects overlayColor in active/pressed/hovered states', (WidgetTester tester) async { |
| 863 | + tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; |
| 864 | + |
| 865 | + const Color fillColor = Color(0xFF000000); |
| 866 | + const Color activePressedOverlayColor = Color(0xFF000001); |
| 867 | + const Color inactivePressedOverlayColor = Color(0xFF000002); |
| 868 | + const Color hoverOverlayColor = Color(0xFF000003); |
| 869 | + const Color hoverColor = Color(0xFF000005); |
| 870 | + |
| 871 | + Color? getOverlayColor(Set<MaterialState> states) { |
| 872 | + if (states.contains(MaterialState.pressed)) { |
| 873 | + if (states.contains(MaterialState.selected)) { |
| 874 | + return activePressedOverlayColor; |
| 875 | + } |
| 876 | + return inactivePressedOverlayColor; |
| 877 | + } |
| 878 | + if (states.contains(MaterialState.hovered)) { |
| 879 | + return hoverOverlayColor; |
| 880 | + } |
| 881 | + return null; |
| 882 | + } |
| 883 | + const double splashRadius = 24.0; |
| 884 | + |
| 885 | + Widget buildCheckbox({bool active = false, bool useOverlay = true}) { |
| 886 | + return MaterialApp( |
| 887 | + theme: ThemeData(useMaterial3: true), |
| 888 | + home: Material( |
| 889 | + child: CheckboxListTile( |
| 890 | + value: active, |
| 891 | + onChanged: (_) { }, |
| 892 | + fillColor: const MaterialStatePropertyAll<Color>(fillColor), |
| 893 | + overlayColor: useOverlay ? MaterialStateProperty.resolveWith(getOverlayColor) : null, |
| 894 | + hoverColor: hoverColor, |
| 895 | + splashRadius: splashRadius, |
| 896 | + ), |
| 897 | + ), |
| 898 | + ); |
| 899 | + } |
| 900 | + |
| 901 | + await tester.pumpWidget(buildCheckbox(useOverlay: false)); |
| 902 | + await tester.startGesture(tester.getCenter(find.byType(Checkbox))); |
| 903 | + await tester.pumpAndSettle(); |
| 904 | + |
| 905 | + expect( |
| 906 | + Material.of(tester.element(find.byType(Checkbox))), |
| 907 | + kIsWeb ? (paints..circle()..circle( |
| 908 | + color: fillColor.withAlpha(kRadialReactionAlpha), |
| 909 | + radius: splashRadius, |
| 910 | + )) : (paints..circle( |
| 911 | + color: fillColor.withAlpha(kRadialReactionAlpha), |
| 912 | + radius: splashRadius, |
| 913 | + )), |
| 914 | + reason: 'Default inactive pressed Checkbox should have overlay color from fillColor', |
| 915 | + ); |
| 916 | + |
| 917 | + await tester.pumpWidget(buildCheckbox(active: true, useOverlay: false)); |
| 918 | + await tester.startGesture(tester.getCenter(find.byType(Checkbox))); |
| 919 | + await tester.pumpAndSettle(); |
| 920 | + |
| 921 | + expect( |
| 922 | + Material.of(tester.element(find.byType(Checkbox))), |
| 923 | + kIsWeb ? (paints..circle()..circle( |
| 924 | + color: fillColor.withAlpha(kRadialReactionAlpha), |
| 925 | + radius: splashRadius, |
| 926 | + )) : (paints..circle( |
| 927 | + color: fillColor.withAlpha(kRadialReactionAlpha), |
| 928 | + radius: splashRadius, |
| 929 | + )), |
| 930 | + reason: 'Default active pressed Checkbox should have overlay color from fillColor', |
| 931 | + ); |
| 932 | + |
| 933 | + await tester.pumpWidget(buildCheckbox()); |
| 934 | + await tester.startGesture(tester.getCenter(find.byType(Checkbox))); |
| 935 | + await tester.pumpAndSettle(); |
| 936 | + |
| 937 | + expect( |
| 938 | + Material.of(tester.element(find.byType(Checkbox))), |
| 939 | + kIsWeb ? (paints..circle()..circle( |
| 940 | + color: inactivePressedOverlayColor, |
| 941 | + radius: splashRadius, |
| 942 | + )) : (paints..circle( |
| 943 | + color: inactivePressedOverlayColor, |
| 944 | + radius: splashRadius, |
| 945 | + )), |
| 946 | + reason: 'Inactive pressed Checkbox should have overlay color: $inactivePressedOverlayColor', |
| 947 | + ); |
| 948 | + |
| 949 | + await tester.pumpWidget(buildCheckbox(active: true)); |
| 950 | + await tester.startGesture(tester.getCenter(find.byType(Checkbox))); |
| 951 | + await tester.pumpAndSettle(); |
| 952 | + |
| 953 | + expect( |
| 954 | + Material.of(tester.element(find.byType(Checkbox))), |
| 955 | + kIsWeb ? (paints..circle()..circle( |
| 956 | + color: activePressedOverlayColor, |
| 957 | + radius: splashRadius, |
| 958 | + )) : (paints..circle( |
| 959 | + color: activePressedOverlayColor, |
| 960 | + radius: splashRadius, |
| 961 | + )), |
| 962 | + reason: 'Active pressed Checkbox should have overlay color: $activePressedOverlayColor', |
| 963 | + ); |
| 964 | + |
| 965 | + // Start hovering |
| 966 | + await tester.pumpWidget(Container()); |
| 967 | + await tester.pumpWidget(buildCheckbox()); |
| 968 | + await tester.pumpAndSettle(); |
| 969 | + |
| 970 | + final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); |
| 971 | + await gesture.addPointer(); |
| 972 | + await gesture.moveTo(tester.getCenter(find.byType(Checkbox))); |
| 973 | + await tester.pumpAndSettle(); |
| 974 | + |
| 975 | + expect( |
| 976 | + Material.of(tester.element(find.byType(Checkbox))), |
| 977 | + paints..circle( |
| 978 | + color: hoverOverlayColor, |
| 979 | + radius: splashRadius, |
| 980 | + ), |
| 981 | + reason: 'Hovered Checkbox should use overlay color $hoverOverlayColor over $hoverColor', |
| 982 | + ); |
| 983 | + }); |
| 984 | + |
829 | 985 | testWidgetsWithLeakTracking('CheckboxListTile respects splashRadius', (WidgetTester tester) async {
|
830 | 986 | tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
831 | 987 | const double splashRadius = 30;
|
@@ -881,7 +1037,7 @@ void main() {
|
881 | 1037 | expect(tester.getSize(find.byType(Checkbox)), const Size(48.0, 48.0));
|
882 | 1038 | });
|
883 | 1039 |
|
884 |
| - testWidgetsWithLeakTracking('CheckboxListTile respects isError - M3', (WidgetTester tester) async { |
| 1040 | + testWidgetsWithLeakTracking('Material3 - CheckboxListTile respects isError', (WidgetTester tester) async { |
885 | 1041 | final ThemeData themeData = ThemeData(useMaterial3: true);
|
886 | 1042 | tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
887 | 1043 | bool? value = true;
|
|
0 commit comments