Unverified Commit 0ed17dd5 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Update `TextSelectionTheme`, `ThemeData`, `TimePicker`, and `TimePickerTheme`...

Update `TextSelectionTheme`, `ThemeData`, `TimePicker`, and `TimePickerTheme` tests for M2/M3 (#130547)

Updated unit tests for `TextSelectionTheme`, `ThemeData`, `TimePicker` and `TimePickerTheme` to have M2 and M3 versions.

More info in #127064
parent d4005a87
......@@ -60,12 +60,11 @@ void main() {
]);
});
testWidgetsWithLeakTracking('Empty textSelectionTheme will use defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData();
final bool material3 = theme.useMaterial3;
final Color defaultCursorColor = material3 ? theme.colorScheme.primary : const Color(0xff2196f3);
final Color defaultSelectionColor = material3 ? theme.colorScheme.primary.withOpacity(0.40) : const Color(0x662196f3);
final Color defaultSelectionHandleColor = material3 ? theme.colorScheme.primary : const Color(0xff2196f3);
testWidgetsWithLeakTracking('Material2 - Empty textSelectionTheme will use defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: false);
const Color defaultCursorColor = Color(0xff2196f3);
const Color defaultSelectionColor = Color(0x662196f3);
const Color defaultSelectionHandleColor = Color(0xff2196f3);
EditableText.debugDeterministicCursor = true;
addTearDown(() {
......@@ -91,6 +90,67 @@ void main() {
// Test the selection handle color.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Builder(
builder: (BuildContext context) {
return materialTextSelectionControls.buildHandle(
context,
TextSelectionHandleType.left,
10.0,
);
},
),
),
),
);
await tester.pumpAndSettle();
final RenderBox handle = tester.firstRenderObject<RenderBox>(find.byType(CustomPaint));
expect(handle, paints..path(color: defaultSelectionHandleColor));
},
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/130469
leakTrackingTestConfig: const LeakTrackingTestConfig(
notDisposedAllowList: <String, int?>{
'ValueNotifier<MagnifierInfo>': 1,
'ValueNotifier<_OverlayEntryWidgetState?>': 2,
'ValueNotifier<bool>': 1,
},
// TODO(polina-c): investigate notGCed, if it does not disappear after fixing notDisposed.
allowAllNotGCed: true,
));
testWidgetsWithLeakTracking('Material3 - Empty textSelectionTheme will use defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
final Color defaultCursorColor = theme.colorScheme.primary;
final Color defaultSelectionColor = theme.colorScheme.primary.withOpacity(0.40);
final Color defaultSelectionHandleColor = theme.colorScheme.primary;
EditableText.debugDeterministicCursor = true;
addTearDown(() {
EditableText.debugDeterministicCursor = false;
});
// Test TextField's cursor & selection color.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Material(
child: TextField(autofocus: true),
),
),
);
await tester.pump();
await tester.pumpAndSettle();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, defaultCursorColor);
expect(renderEditable.selectionColor, defaultSelectionColor);
// Test the selection handle color.
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: Builder(
builder: (BuildContext context) {
......
......@@ -14,9 +14,8 @@ void main() {
const ShapeBorder defaultFABShapeM3 = RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)));
const EdgeInsets defaultFABPadding = EdgeInsets.zero;
testWidgets('theme: ThemeData.light(), enabled: true', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light();
final bool material3 = theme.useMaterial3;
testWidgets('Material2 - theme: ThemeData.light(), enabled: true', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light(useMaterial3: false);
await tester.pumpWidget(
MaterialApp(
theme: theme,
......@@ -31,21 +30,48 @@ void main() {
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, true);
expect(raw.textStyle!.color, material3 ? theme.colorScheme.onPrimaryContainer : const Color(0xffffffff));
expect(raw.fillColor, material3 ? theme.colorScheme.primaryContainer : const Color(0xff2196f3));
expect(raw.textStyle!.color, const Color(0xffffffff));
expect(raw.fillColor, const Color(0xff2196f3));
expect(raw.elevation, 6.0);
expect(raw.highlightElevation, material3 ? 6.0 : 12.0);
expect(raw.highlightElevation, 12.0);
expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding);
expect(raw.shape, material3 ? defaultFABShapeM3 : defaultFABShape);
expect(raw.shape, defaultFABShape);
expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
});
testWidgets('theme: ThemeData.light(), enabled: false', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light();
final bool material3 = theme.useMaterial3;
testWidgets('Material3 - theme: ThemeData.light(), enabled: true', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Center(
child: FloatingActionButton(
onPressed: () { }, // button.enabled == true
child: const Icon(Icons.add),
),
),
),
);
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, true);
expect(raw.textStyle!.color, theme.colorScheme.onPrimaryContainer);
expect(raw.fillColor, theme.colorScheme.primaryContainer);
expect(raw.elevation, 6.0);
expect(raw.highlightElevation, 6.0);
expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding);
expect(raw.shape, defaultFABShapeM3);
expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
});
testWidgets('Material2 - theme: ThemeData.light(), enabled: false', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light(useMaterial3: false);
await tester.pumpWidget(
MaterialApp(
theme: theme,
......@@ -60,16 +86,46 @@ void main() {
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, false);
expect(raw.textStyle!.color, material3 ? theme.colorScheme.onPrimaryContainer : const Color(0xffffffff));
expect(raw.fillColor, material3 ? theme.colorScheme.primaryContainer : const Color(0xff2196f3));
expect(raw.textStyle!.color, const Color(0xffffffff));
expect(raw.fillColor, const Color(0xff2196f3));
// highlightColor, disabled button can't be pressed
// splashColor, disabled button doesn't splash
expect(raw.elevation, 6.0);
expect(raw.highlightElevation, 12.0);
expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding);
expect(raw.shape, defaultFABShape);
expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
});
testWidgets('Material3 - theme: ThemeData.light(), enabled: false', (WidgetTester tester) async {
final ThemeData theme = ThemeData.light(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: const Center(
child: FloatingActionButton(
onPressed: null, // button.enabled == false
child: Icon(Icons.add),
),
),
),
);
final RawMaterialButton raw = tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
expect(raw.enabled, false);
expect(raw.textStyle!.color, theme.colorScheme.onPrimaryContainer);
expect(raw.fillColor, theme.colorScheme.primaryContainer);
// highlightColor, disabled button can't be pressed
// splashColor, disabled button doesn't splash
expect(raw.elevation, 6.0);
expect(raw.highlightElevation, material3 ? 6.0 : 12.0);
expect(raw.highlightElevation, 6.0);
expect(raw.disabledElevation, 6.0);
expect(raw.constraints, defaultFABConstraints);
expect(raw.padding, defaultFABPadding);
expect(raw.shape, material3 ? defaultFABShapeM3 : defaultFABShape);
expect(raw.shape, defaultFABShapeM3);
expect(raw.animationDuration, defaultButtonDuration);
expect(raw.materialTapTargetSize, MaterialTapTargetSize.padded);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment